Replace all instances of ; in the rowparser loop with , ( ~15% speedup )
[dbsrgits/DBIx-Class.git] / examples / Benchmarks / semicolon_vs_comma_rowparser / sloppy_bench.pl
diff --git a/examples/Benchmarks/semicolon_vs_comma_rowparser/sloppy_bench.pl b/examples/Benchmarks/semicolon_vs_comma_rowparser/sloppy_bench.pl
new file mode 100644 (file)
index 0000000..fb12fb8
--- /dev/null
@@ -0,0 +1,28 @@
+use warnings;
+use strict;
+
+use Benchmark qw( cmpthese :hireswallclock);
+use Sereal;
+use Devel::Dwarn;
+
+my ($semicol, $comma) = map {
+  my $src = do { local (@ARGV, $/) = $_; <> };
+  eval "sub { use strict; use warnings; use warnings FATAL => 'uninitialized'; $src }" or die $@;
+} qw( semicol.src comma.src );
+
+my $enc = Sereal::Encoder->new;
+my $dec = Sereal::Decoder->new;
+
+for my $iters ( 100, 10_000, 100_000 ) {
+  my $dataset = [];
+  push @$dataset, [ (scalar @$dataset) x 11 ]
+    while @$dataset < $iters;
+
+  my $ice = $enc->encode($dataset);
+
+  print "\nTiming $iters 'rows'...\n";
+  cmpthese( -10, {
+    semicol => sub { $semicol->($dec->decode($ice)) },
+    comma => sub { $comma->($dec->decode($ice)) },
+  })
+}