Skip to content

Instantly share code, notes, and snippets.

@sandrokeil
Created December 2, 2017 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sandrokeil/7574741e35ba92bc7a19aad06e35d4b6 to your computer and use it in GitHub Desktop.
Save sandrokeil/7574741e35ba92bc7a19aad06e35d4b6 to your computer and use it in GitHub Desktop.
vpack benchmark test #1
<?php
require 'vendor/autoload.php';
use ArangoDb\Vpack;
use ProophTest\EventStore\Mock\TestDomainEvent;
$payload = [
'key1' => 'value1',
'key2' => 2,
'key3' => 'some@mail.com',
'key4' => 'value4',
'key5' => true,
'key6' => false,
'key7' => 7,
];
$start = microtime(true);
for ($j = 0; $j < 10; $j++) {
for ($i = 0; $i < 100; $i++) {
$data = json_encode(TestDomainEvent::with($payload, $i));
}
}
$end = microtime(true);
$time = $end - $start;
echo "json_encode: $time s" . PHP_EOL;
$start = microtime(true);
for ($j = 0; $j < 10; $j++) {
for ($i = 0; $i < 100; $i++) {
$data = Vpack::fromJson(json_encode(TestDomainEvent::with($payload, $i)));
}
}
$end = microtime(true);
$time = $end - $start;
echo "Vpack::fromJson: $time s" . PHP_EOL;
$start = microtime(true);
for ($j = 0; $j < 10; $j++) {
for ($i = 0; $i < 100; $i++) {
$data = Vpack::fromArray(TestDomainEvent::with($payload, $i)->toArray());
}
}
$end = microtime(true);
$time = $end - $start;
echo "Vpack::fromArray: $time s" . PHP_EOL;
@sandrokeil
Copy link
Author

sandrokeil commented Dec 2, 2017

json_encode: 0.30263495445251 s
Vpack::fromJson: 0.43449902534485 s
Vpack::fromArray: 0.35646820068359 s

some fluctuations:

json_encode: 0.29366707801819 s
Vpack::fromJson: 0.3661630153656 s
Vpack::fromArray: 0.33927893638611 s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment