in reply to Number gussing game

I remember I read about adding brackets after the function call but I just forgot to add them :D however, I don't like removing the ampersand, i think it helps distinguish the difference between user defined functions and built-in function... I will actually do that, even though I don't know a lot about the <=> :D but using -1, 0, and 1 makes more sense than using 0, 1, and 2... It's just that considering it's just a loop, i think it should run faster than this!

Replies are listed 'Best First'.
Re^2: Number gussing game
by GrandFather (Saint) on Jun 28, 2007 at 22:35 UTC

    How are you timing it? Consider:

    print time, "\n"; 1 for 1 .. 1000000000; print time, "\n";

    is just a loop, but takes a while to run (about 48 seconds on my system) and can be timed accurately enough as shown. You loop executes in about 10 micro seconds (timed over 1 million iterations) which doesn't seem excessively slow to me.


    DWIM is Perl's answer to Gödel
      May be it's a problem in my pc, the loop took 184 seconds, which is almost 4 times slower than your machine :) Thank you all for your participation, Cheers!

        So your number guessing program would take about 4/1000 of a second to chech the 100 numbers on your system. That doesn't sound too long to wait. What's the problem and again: how did you time it?


        DWIM is Perl's answer to Gödel