in reply to Re: Teach him a lesson with facts
in thread Teach him a lesson with facts
#!/usr/bin/perl use Benchmark qw(cmpthese timethese); sub iterate { open(FILE, ">", "file.txt"); for ($i = 0; $i < 1000000; $i ++) { print FILE $i++; } close(FILE); } sub lex_iterate { open(FILE, ">", "file.txt"); for (my $i = 0; $i < 1000000; $i ++) { print FILE $i++; } close(FILE); } sub int_iterate { use integer; open(FILE, ">", "file.txt"); for (my $i = 0; $i < 1000000; $i ++) { print FILE $i++; } close(FILE); } my $results = timethese(5 , { iterate=>\&iterate , lex_iterate=>\&lex_ +iterate, int_iterate=>\&int_iterate } ); cmpthese($results); __END__ Benchmark: timing 5 iterations of int_iterate, iterate, lex_iterate... int_iterate: 4 wallclock secs ( 4.03 usr + 0.06 sys = 4.09 CPU) @ +1.22/s (n=5) iterate: 17 wallclock secs (16.70 usr + 0.07 sys = 16.77 CPU) @ 0 +.30/s (n=5) lex_iterate: 15 wallclock secs (15.20 usr + 0.08 sys = 15.28 CPU) @ +0.33/s (n=5) s/iter iterate lex_iterate int_iterate iterate 3.35 -- -9% -76% lex_iterate 3.06 10% -- -73% int_iterate 0.818 310% 2
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re(2): Lesson Taught
by Anonymous Monk on Feb 23, 2003 at 06:20 UTC | |
by shotgunefx (Parson) on Feb 23, 2003 at 09:26 UTC | |
by Anonymous Monk on Feb 23, 2003 at 17:46 UTC | |
by shotgunefx (Parson) on Feb 24, 2003 at 05:09 UTC | |
by Anonymous Monk on Feb 24, 2003 at 06:00 UTC | |
| |
by Anonymous Monk on Feb 23, 2003 at 06:28 UTC |