Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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

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


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

The same number of int takes less than 1 second to initialize

Isn't 15 secs too much time even though a scalar requires more storage(16 bytes after test) than int?

Replies are listed 'Best First'.
Re^7: Why it takes so much time here?
by ikegami (Pope) on Dec 28, 2011 at 05:19 UTC

    The same number of int takes less than 1 second to initialize

    What does that mean?

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

      My original question still remains,right?

        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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://945283]
help
Chatterbox?
[shmem]: in the french alpes, at the end of a gravel road, we had a beer at a hut - and heard an enduro coming up.
[shmem]: not by the road, but from there below where you wouldn't want to walk.
[shmem]: the biker stopped the machine at the table and took off his helmet.
[shmem]: long white hair, long beard the same, then he proceeded to get off the bike
[shmem]: saying "biking itself isn't that much, but getting up and down - hell!"
[shmem]: up and down: on and off the bike, of course

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2017-06-25 20:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (570 votes). Check out past polls.