-1

Just a general performance question. Is 1-7 seconds a good build time for a program that builds a poker hand, sorts a poker hand, analyzes and then returns every poker hand type such as straight, flushes etc. etc?

I am generating a hand until it returns a hand type, in the process i sort it from lowest to highest rank. I am doing this for every poker hand type. so you can imagine to generate a royal flush and straight flush, it has to generate thousands of hands before striking.

How do I know that the time it is taking to do the analysis is reasonable?

casperOne
  • 73,706
  • 19
  • 184
  • 253
  • This is a really tough question to answer without any specific code. I'd say that's too long though... – kentcdodds May 18 '12 at 01:52
  • 2
    Impossible to say without looking at the code. This is highly dependent on language, hardware, and implementation. – Mike Bailey May 18 '12 at 01:52
  • I ran it about 25 times, it averaged about 3 seconds, no good? – user1051043 May 18 '12 at 02:04
  • if your players are willing to wait 3 seconds, it's fine... however, as I said below, there is no reason for this process to be anything other instantaneous. – Yevgeny Simkin May 18 '12 at 02:05
  • "Build time": the time for the compiler to build the program, or the time for the program to build and rate the poker hand - which I would call "execution time?" – Skip Head May 18 '12 at 02:11
  • The issue really comes when it gets to checking if the user has a Straight Flush and then the Royal Flush. So I'm going to focus on optimizing those methods. – user1051043 May 18 '12 at 02:15
  • The time for program to build the hand, sort the hand, check the hand and then display each of the different poker hand types. At the bottom of the IDE is says build time, which I am using netbeans – user1051043 May 18 '12 at 02:16
  • I actually voted to close this, but I have a good answer and want to reopen it. I think I understand this question better now. OP wants to know how to tell if an application is optimized for execution time. – Erick Robertson May 18 '12 at 02:46
  • @Erick: Disagree, this belongs closed. If anything, perhaps I could see this being moved to programmers, but it's not really a good question for this site... – ircmaxell May 18 '12 at 03:18
  • @ErickRobertson: If you have an answer to figure out what a reasonable time is please provide, thanks for your help? – user1051043 May 18 '12 at 03:40

2 Answers2

2

That's way too long I'd say. Unless you've got a complicated GUI... I recommend taking performance related questions to CodeReview. Give them a good SSCCE, or at least a method or two you're focusing on and you're likely to get a good response.

Also, you may consider benchmarking. Here's a good question about that. Caliper is a really great benchmarking framework I recommend looking into as well (I learned about it on CodeReview ;D)

Community
  • 1
  • 1
kentcdodds
  • 27,113
  • 32
  • 108
  • 187
1

No... Poker doesn't have very many options, there's no reason for such an analyzer to take anywhere near a second, much less 7. About 7 years ago I wrote a Hold'em game for Brew (C) handsets. It would generate hands (just about) instantly. If you're in java then you're probably running on a fairly modern (read SUPER fast) machine, regardless of whether it's a modern phone or a server, generating and evaluating poker hands is not a time consuming enterprise.

Yevgeny Simkin
  • 27,946
  • 39
  • 137
  • 236
  • I would be more then willing to send a zip file with all the files. I have numerous classes so it would be impossible to show here. – user1051043 May 18 '12 at 01:55
  • 1
    I'm not going to review your code, but the obvious solution here is this: draw cards from a 52 card deck (assuming your deck is just an array of Card this will be lightning fast). Try to find the best hand possible (in best to worst order), cause if they have a Flush, there's no point in looking for a straight. Again, each hand individually should be imperceptibly fast to calculate, and there are only 9 hands, so if your program is taking any perceptible time at all you're doing something terribly wrong. – Yevgeny Simkin May 18 '12 at 02:02
  • No here is the thing, I am generating a hand until it returns a hand type, in the process i sort it from lowest to highest rank. I am doing this for every poker hand type. so you can imagine to generate a royal flush and straight flush, it has to generate thousands of hands before striking. – user1051043 May 18 '12 at 02:17
  • well... I can't imagine why you're doing this. If you need a straight you can pull a random card and then 4 cards around it (in random directions). If you want 3 of a kind, pull a random card of a random suit, and then 2 of the remaining suited cards of that rank... etc. You can generate any random hand instantly... so... if you want a random hand of a specific kind you can getHand(rand * 9). This will generate a random hand of SOME type, and again, it will happen instantly. – Yevgeny Simkin May 18 '12 at 05:07