#!/usr/bin/perl use strict; use warnings; use YAML; use YAML::Syck; use YAML::XS; my $count = 100_000; my $count_xs = 1_000_000; my $yml = <<'TXT'; --- session_code: 649e116d890ad16306ef8d4491029db9 country: xx exchrate: 33.81 id: 1234567 message: xxxxx number: 1234 operator: xxxxx operator_full: xxxxxx phone: 7701xxxxxxx plain: xxxxx price: 12.34567 TXT my $dump = YAML::Load($yml); my ($t, $s) = (0,0); ########################################################### $t = time(); foreach (1..$count) { my $y = YAML::Load($yml); } $t = time() - $t; $s = int($count/$t); print "YAML::Load: time: $t sec; speed: $s req/sec\n"; $t = time(); foreach (1..$count) { my $y = YAML::Dump($dump); } $t = time() - $t; $s = int($count/$t); print "YAML::Dump: time: $t sec; speed: $s req/sec\n"; ########################################################### $t = time(); foreach (1..$count_xs) { my $y = YAML::Syck::Load($yml); } $t = time() - $t; $s = int($count_xs/$t); print "YAML::Syck::Load: time: $t sec; speed: $s req/sec\n"; $t = time(); foreach (1..$count_xs) { my $y = YAML::Syck::Dump($dump); } $t = time() - $t; $s = int($count_xs/$t); print "YAML::Syck::Dump: time: $t sec; speed: $s req/sec\n"; ########################################################### $t = time(); foreach (1..$count_xs) { my $y = YAML::XS::Load($yml); } $t = time() - $t; $s = int($count_xs/$t); print "YAML::XS::Load: time: $t sec; speed: $s req/sec\n"; $t = time(); foreach (1..$count_xs) { my $y = YAML::XS::Dump($dump); } $t = time() - $t; $s = int($count_xs/$t); print "YAML::XS::Dump: time: $t sec; speed: $s req/sec\n"; print "DONE\n";