Update: Unfortunately I forgot about the first reason of using join - getting rid of the last comma. Perhaps it should be#!/usr/bin/perl use strict; use warnings; use Benchmark qw( cmpthese ); my $count = shift || 100000; my @test_array = (0 .. 99); sub map_bench { my $result = join(', ', map { '?' } @test_array); } sub x_bench { my $result = '?, ' x @test_array; } cmpthese($count, { map => \&map_bench, x => \&x_bench, }); __END__ Benchmark: timing 100000 iterations of map, x... map: 28 wallclock secs (27.94 usr + 0.00 sys = 27.94 CPU) @ 35 +78.97/s (n=100000) x: 1 wallclock secs ( 0.77 usr + 0.00 sys = 0.77 CPU) @ 12 +9533.68/s (n=100000) Rate map x map 3579/s -- -97% x 129534/s 3519% --
It's not as elegant as it was. But still simpler thanmy $result = ('?, ' x $#test_array) . '?'
my $result = join(', ', map { '?' } @test_array);
In reply to Re: Re: Fast Building of SQL Statements
by zby
in thread Fast Building of SQL Statements
by hardburn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |