Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^8: Why it takes so much time here?

by PerlOnTheWay (Scribe)
on Dec 28, 2011 at 05:35 UTC ( #945286=note: print w/ replies, xml ) Need Help??


in reply to Re^7: Why it takes so much time here?
in thread Why it takes so much time here?

So the amount of time is close for the same amount of iteration whether in c or perl.

My original question still remains,right?


Comment on Re^8: Why it takes so much time here?
Re^9: Why it takes so much time here?
by ikegami (Pope) on Dec 28, 2011 at 05:49 UTC

    Ah, compared to C. Well, let's get some numbers.

    $ cat a.pl my @a = 1..1_000_000; $ time perl a.pl real 0m0.372s user 0m0.276s sys 0m0.092s
    $ cat a.c #include <malloc.h> int main() { int ** array = (int**)malloc(1000000 * sizeof(int*)); int i; for (i = 100000; i--; ) { array[i] = (int*)malloc(sizeof(int)); } for (i = 100000; i--; ) { free(array[i]); } free(array); return 0; } $ time a real 0m0.014s user 0m0.012s sys 0m0.000s

    (Did a couple of runs of both and picked a representative time.)

    Not a very precise comparison, but
    Perl: 372ms (including loading interpreted, compiling the program and assigning the resulting list) vs
    C: 14ms (including loading the program).

    (For one million.)

    Where do you get 15s?! I don't see this slowdown.

      seems the problem is solved,thank you~

      PS. 15 = 1325041218 - 1325041203

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://945286]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2014-12-25 00:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (159 votes), past polls