#!/usr/bin/perl use strict; use warnings; use Benchmark qw(cmpthese :hireswallclock); my $coords = 'lon,lat,alt ' x 20000; cmpthese(100, { OP => sub { my @list = split(/[, ]/,$coords); my $size = @list; my @poly = (); for (my $i=0; $i<=($size-3); $i+=3) { my $lon = $list[$i+0]; my $lat = $list[$i+1]; my $point = [$lon,$lat]; push (@poly, $point); } }, double_split => sub { my @list = split(' ',$coords); my @poly; $poly[@list-1] = 0; for (@list) { push (@poly, [ (split /,/, $_)[0, 1] ]); } }, while_shift => sub { my @list = split(/[, ]/,$coords); my @poly = (); while (@list) { push @poly, [shift @list, shift @list]; shift @list; } }, regex => sub { my @poly = (); while ($coords =~ /([^,]+),([^,]+),[^\s]+ /g) { push @poly, [$1,$2]; } }, chromatic => sub { my @poly = map { [ (split /,/, $_)[0, 1] ] } split / /, $coords;}, jwkrahn => sub { my @poly = map [ ( split /,/ )[ 0, 1 ] ], split ' ', $coords;}, ike1 => sub { my @poly = map [ (split /,/, $_)[0, 1] ], split ' ', $coords;}, ike2 => sub { my @poly = map [ /([^,]*),([^,]*)/ ], split ' ', $coords; }, }); __END__ Rate OP while_shift double_split ike1 jwkrahn chromatic ike2 regex OP 6.14/s -- -17% -49% -50% -51% -52% -54% -59% while_shift 7.42/s 21% -- -38% -40% -40% -42% -45% -51% double_split 11.9/s 95% 61% -- -3% -4% -7% -11% -21% ike1 12.3/s 101% 66% 3% -- -1% -4% -8% -18% jwkrahn 12.4/s 103% 67% 4% 1% -- -3% -8% -18% chromatic 12.9/s 109% 73% 8% 4% 3% -- -4% -15% ike2 13.4/s 119% 81% 13% 9% 8% 5% -- -11% regex 15.1/s 147% 104% 27% 23% 22% 18% 13% --