--eakHere are my benchmark results: join: 2 wallclock secs ( 1.68 usr + 0.00 sys = 1.68 CPU) loop: 8 wallclock secs ( 7.60 usr + 0.02 sys = 7.62 CPU)
#!/usr/bin/perl -w use Benchmark; my @a1 = qw(3 99 4 33 43 98 83 64 3 99 4 33 43 98 83 64 99 4 33 43 98 + 83 64); my @a2 = qw(3 99 4 33 43 98 83 64 3 99 4 33 43 98 83 64 99 4 33 43 98 + 83 64); sub join_eq { return join('',@a1) eq join('', @a2); } sub loop_eq { my $rc = 1; if ($#a1 != $#a2) { $rc = 0; } else { for (my $i=0; $i<=$#a1; $i++) { $rc = 0 if $a1[$i] ne $a2[$i]; } } return $rc; } timethese(100000, {join => \&join_eq, loop => \&loop_eq});
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Comparing Arrays
by lhoward (Vicar) on Sep 01, 2000 at 22:41 UTC | |
|
RE: Comparing Arrays
by Boogman (Scribe) on Sep 01, 2000 at 22:45 UTC | |
by btrott (Parson) on Sep 01, 2000 at 22:51 UTC | |
by lhoward (Vicar) on Sep 01, 2000 at 23:00 UTC | |
by jlistf (Monk) on Sep 01, 2000 at 23:09 UTC | |
by merlyn (Sage) on Sep 01, 2000 at 23:12 UTC | |
|
RE: Comparing Arrays
by davorg (Chancellor) on Sep 02, 2000 at 00:17 UTC | |
|
RE: Comparing Arrays
by b (Beadle) on Sep 01, 2000 at 23:07 UTC | |
|
RE: Comparing Arrays
by Adam (Vicar) on Sep 01, 2000 at 23:08 UTC | |
|
RE: Comparing Arrays
by Boogman (Scribe) on Sep 01, 2000 at 23:58 UTC | |
|
RE: Comparing Arrays
by fundflow (Chaplain) on Sep 02, 2000 at 02:03 UTC |