Skip to content

Instantly share code, notes, and snippets.

$ bencher -m Serializers --include-participant JSON::XS::encode_json --include-participant JSON::Create::create_json
+-----+---------------------------------------------------------------------+------------------+-------------+---------+----------------------+
| seq | name | rate | time | samples | errors |
+-----+---------------------------------------------------------------------+------------------+-------------+---------+----------------------+
| 26 | {dataset=>"hash_int1000",participant=>"JSON::Create::create_json"} | 3667.15927605996 | 272.69064μs | 21 | 2.60136033397983e-07 |
| 8 | {dataset=>"hash_int1000",participant=>"JSON::XS::encode_json"} | 4920.50226487789 | 203.23129μs | 21 | 1.56081669207923e-07 |
| 23 | {dataset=>"array_int1000",participant=>"JSON::Create::create_json"} | 8285.40960986281 | 120.69409μs | 29 | 4.42734326540696e-08 |
| 5 | {dataset=>"array_int1000",particip
@perlancar
perlancar / gist:927e7f96e1e12111eb52
Created April 7, 2015 06:25
Benchmark::Serialize result
% perl -MBenchmark::Serialize=cmpthese -E'my $struct={array=>["a".."j"], hash=>{"a".."z"}, string=>"x" x 200}; cmpthese(-1, $struct, qw(:all))'
...
Roundtrip
Rate PHP::Serialization YAML::Tiny JSON::PP Convert::Bencode Data::Dumper YAML::XS Storable JSON::XS,pretty JSON::XS
PHP::Serialization 956/s -- -49% -57% -80% -92% -94% -98% -99% -99%
YAML::Tiny 1879/s 96% -- -16% -60% -84% -88% -97% -98% -99%
JSON::PP 2241/s 134% 19% -- -52% -80% -85% -96% -98% -98%
Convert::Bencode 4697/s 391% 150% 110% -- -59% -69% -92% -96% -96%
Data::Dumper 11395/s 1091% 506% 408% 143% -- -26% -81% -89%
#!/usr/bin/perl
use strict;
use warnings;
use Log::Any '$log';
$log->info("Setting up");
my $pos=0;
#!/usr/bin/perl
use strict;
use warnings;
use Progress::Any;
use Progress::Any::Output;
Progress::Any::Output->set('TermProgressBarColor');
{
extended => [
{
ip => "65.182.224.220", # ..{0}
ip_family => "ipv4", # ..{1}
mac => "00:00:00:00:00:00", # ..{2}
type => "static", # ..{3}
}, # .[0]
{
ip => "65.182.224.218", # ..{ 0}
{
extended => [
{
ip => "213.105.69.252", # ..{0}
ip_type => "DHCPRELAY", # ..{1}
mac => "00:19:bf:82:4c:3c", # ..{2}
vlan => "N1-1-VB4-VLAN8", # ..{3}
}, # .[0]
], # {0}
int => "N2-1-1-10", # {1}
Revision history for Mo
0.37 Fri Oct 25 21:46:59 MYT 2013
[Bugfix]
- Run Test::Compile tests as xt as they require optional dependencies to
be present (GH issue
[Makefile]
- Added target to update version on all packages
# SORTED FROM SLOWEST TO FASTEST
# Params::Validate
$ perl -MParams::Validate=:all -MBench -e'%spec = (a=>{type=>SCALAR, regex=>qr/^\d+$/, callbacks=>{"min 1"=>sub{shift() >= 1}}, default=>1}); @ary = (a=>1); bench sub { validate(@ary, \%spec) }, -2'
333331 calls (155860/s), 2.139s (0.0064ms/call)
# Data::Sah
$ perl -MBench -MData::Sah=gen_validator -e'$v=gen_validator(["hash*"=>keys=>{a=>["int*", min=>1]}], {return_type=>"str"}); bench sub { $v->({a=>1}) }, -2'
411762 calls (183012/s), 2.250s (0.0055ms/call)
# SORTED FROM SLOWEST TO FASTEST
# Data::Validation
$ perl -MBench -e'package P; use Validation::Class; field f1=> {required=>1}; field f2=>{required=>1}; field f3=>{}; package main; my $p=P->new(f1=>1, f2=>2); bench sub { $p->validate(qw/f1 f2 f3/) }, -2'
8449 calls (4030/s), 2.097s (0.248ms/call)
# Data::Domain 1.01 (also not exactly equivalent, can't assign default value)
$ perl -MBench -MData::Domain=:all -E'$d=Struct(a => Whatever(-defined=>1), b=>Whatever(-defined=>1), c=>Whatever); bench sub { {} ~~ $d }, -2'
14061 calls (6642/s), 2.117s (0.151ms/call)
Testing App::Nopaste #4