in reply to Request for further enlightenment
Ran for default 3 CPU seconds:#!/usr/bin/perl -w use Benchmark ; use strict; my $count = shift || "-3" ; # set the test counter my @array = (); #load up an array of crap for ( my $i = 0; $i < 1000; $i++) { push @array, rand(256); } open NULL, "+/dev/null" or die "$!"; timethese ( $count, { 'join' => '&print_join', 'map' => '&print_map', 'field sep' => '&print_field' } ); # use join to print each array elemnet. sub print_join { print NULL join("\n", @array) ; } # use map to print each array elemnt, sub print_map { print NULL map{ $_ .= "\n"} @array ; } # use map to print each array elemnt, sub print_field { local $,="\n"; print NULL @array ; }
./time_print
Benchmark: running field sep, join, map, each for at least 3 CPU seconds...
field sep: 3 wallclock secs ( 3.15 usr + 0.00 sys = 3.15 CPU) @ 53645.71/s (n=168984)
join: 3 wallclock secs ( 3.05 usr + 0.01 sys = 3.06 CPU) @ 1256.86/s (n=3846)
map: 5 wallclock secs ( 4.56 usr + 0.04 sys = 4.60 CPU) @ 119.78/s (n=551)
looks like the field sepperator is the fastest with 53,645.71 /sec
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Request for further enlightenment
by Juerd (Abbot) on Jun 05, 2002 at 08:06 UTC | |
by MeowChow (Vicar) on Jun 05, 2002 at 08:21 UTC | |
by yodabjorn (Monk) on Jun 05, 2002 at 18:22 UTC |