in reply to System call problem
a quick benchmark on my system shows the localtime method is 39 times faster than the system call to date method:my ($day,$mon,$year)=(localtime(time))[3,4,5]; my $date=sprintf("%0d%02d%02d",$year+1900,$mon+1,$day);
localtime: 4 wallclock secs ( 3.10 usr + 0.06 sys = 3.16 CPU) @ 30622.78/s (n=96768) sysdate: 31 wallclock secs ( 0.38 usr 3.65 sys + 11.15 cusr 2.36 csys = 17.54 CPU) @ 767.25/s (n=3092)using
#!/usr/bin/perl -w use strict; use Benchmark; timethese(0, { sysdate => "chomp( my \$date = `date +\%Y\%m\%d` );", localtime => 'my ($day,$mon,$year)=(localtime(time) +)[3,4,5]; my $date=sprintf("%0d%02d%02d",$year+1900,$mon+1,$day);', });
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: System call problem
by Gloom (Monk) on Mar 08, 2001 at 20:40 UTC |