Skip to content

Instantly share code, notes, and snippets.

@PyYoshi
Last active August 29, 2015 14:24
Show Gist options
  • Save PyYoshi/57e2ccc5626fce92f7cf to your computer and use it in GitHub Desktop.
Save PyYoshi/57e2ccc5626fce92f7cf to your computer and use it in GitHub Desktop.

lsb_release -a

No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 15.04
Release:	15.04
Codename:	vivid

cat /proc/cpuinfo

processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 69
model name	: Intel(R) Core(TM) i7-4650U CPU @ 1.70GHz
stepping	: 1
microcode	: 0x1c
cpu MHz		: 3234.195
cache size	: 4096 KB
physical id	: 0
siblings	: 4
core id		: 0
cpu cores	: 2
apicid		: 0
initial apicid	: 0
fpu		: yes
fpu_exception	: yes
cpuid level	: 13
wp		: yes
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm ida arat epb pln pts dtherm tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt
bugs		:
bogomips	: 4600.04
clflush size	: 64
cache_alignment	: 64
address sizes	: 39 bits physical, 48 bits virtual
power management:

processor	: 1
vendor_id	: GenuineIntel
cpu family	: 6
model		: 69
model name	: Intel(R) Core(TM) i7-4650U CPU @ 1.70GHz
stepping	: 1
microcode	: 0x1c
cpu MHz		: 3060.437
cache size	: 4096 KB
physical id	: 0
siblings	: 4
core id		: 1
cpu cores	: 2
apicid		: 2
initial apicid	: 2
fpu		: yes
fpu_exception	: yes
cpuid level	: 13
wp		: yes
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm ida arat epb pln pts dtherm tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt
bugs		:
bogomips	: 4600.04
clflush size	: 64
cache_alignment	: 64
address sizes	: 39 bits physical, 48 bits virtual
power management:

processor	: 2
vendor_id	: GenuineIntel
cpu family	: 6
model		: 69
model name	: Intel(R) Core(TM) i7-4650U CPU @ 1.70GHz
stepping	: 1
microcode	: 0x1c
cpu MHz		: 3000.601
cache size	: 4096 KB
physical id	: 0
siblings	: 4
core id		: 0
cpu cores	: 2
apicid		: 1
initial apicid	: 1
fpu		: yes
fpu_exception	: yes
cpuid level	: 13
wp		: yes
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm ida arat epb pln pts dtherm tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt
bugs		:
bogomips	: 4600.04
clflush size	: 64
cache_alignment	: 64
address sizes	: 39 bits physical, 48 bits virtual
power management:

processor	: 3
vendor_id	: GenuineIntel
cpu family	: 6
model		: 69
model name	: Intel(R) Core(TM) i7-4650U CPU @ 1.70GHz
stepping	: 1
microcode	: 0x1c
cpu MHz		: 2982.453
cache size	: 4096 KB
physical id	: 0
siblings	: 4
core id		: 1
cpu cores	: 2
apicid		: 3
initial apicid	: 3
fpu		: yes
fpu_exception	: yes
cpuid level	: 13
wp		: yes
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm ida arat epb pln pts dtherm tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt
bugs		:
bogomips	: 4600.04
clflush size	: 64
cache_alignment	: 64
address sizes	: 39 bits physical, 48 bits virtual
power management:

cat /proc/meminfo

MemTotal:        8114616 kB
MemFree:         2322128 kB
MemAvailable:    3754780 kB
Buffers:          144784 kB
Cached:          2033124 kB
SwapCached:            0 kB
Active:          4105300 kB
Inactive:        1402316 kB
Active(anon):    3333392 kB
Inactive(anon):   620740 kB
Active(file):     771908 kB
Inactive(file):   781576 kB
Unevictable:          60 kB
Mlocked:              60 kB
SwapTotal:       4802556 kB
SwapFree:        4802556 kB
Dirty:               184 kB
Writeback:             0 kB
AnonPages:       3329760 kB
Mapped:           598216 kB
Shmem:            624432 kB
Slab:             140428 kB
SReclaimable:      96204 kB
SUnreclaim:        44224 kB
KernelStack:       12736 kB
PageTables:        62300 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     8859864 kB
Committed_AS:   12236612 kB
VmallocTotal:   34359738367 kB
VmallocUsed:      457220 kB
VmallocChunk:   34359224936 kB
HardwareCorrupted:     0 kB
AnonHugePages:   1341440 kB
CmaTotal:              0 kB
CmaFree:               0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:      193188 kB
DirectMap2M:     7086080 kB
DirectMap1G:     1048576 kB
## EncoderBench
string escaping (JSX, unsupported) 1000000000 0.01 µs/op
maps (jiffy) 500000 8.67 µs/op
maps (JSX) 50000 73.57 µs/op
strings (jiffy) 20000 99.95 µs/op
maps (Poison) 10000 111.05 µs/op
string escaping (jiffy) 10000 147.79 µs/op
maps (Jazz) 10000 176.39 µs/op
lists (jiffy) 10000 191.44 µs/op
strings (Poison) 10000 251.14 µs/op
strings (JSX) 5000 333.83 µs/op
jiffy 5000 425.94 µs/op
strings (Jazz) 5000 436.74 µs/op
string escaping (Poison) 1000 1342.62 µs/op
lists (Poison) 1000 1376.51 µs/op
string escaping (Jazz) 1000 1664.06 µs/op
lists (Jazz) 1000 1762.38 µs/op
lists (JSX) 1000 1813.08 µs/op
JSX 500 4652.86 µs/op
Poison 500 4954.82 µs/op
Jazz 500 7968.03 µs/op
## ParserBench
UTF-8 unescaping (jiffy) 50000 73.19 µs/op
UTF-8 unescaping (Poison) 5000 346.74 µs/op
UTF-8 unescaping (JSX) 5000 466.73 µs/op
jiffy 5000 635.26 µs/op
Poison 1000 1264.78 µs/op
JSX 1000 2004.61 µs/op
<?php
/*
* Copyright (c) 2012 Jeremy Perret
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
class Ubench
{
protected $start_time;
protected $end_time;
protected $memory_usage;
/**
* Sets start microtime
*
* @return void
*/
public function start()
{
$this->start_time = microtime(true);
}
/**
* Sets end microtime
*
* @return void
*/
public function end()
{
$this->end_time = microtime(true);
$this->memory_usage = memory_get_usage(true);
}
/**
* Returns the elapsed time, readable or not
*
* @param boolean $readable Whether the result must be human readable
* @param string $format The format to display (printf format)
* @return string|float
*/
public function getTime($raw = false, $format = null)
{
$elapsed = $this->end_time - $this->start_time;
return $raw ? $elapsed : self::readableElapsedTime($elapsed, $format);
}
/**
* Returns the memory usage at the end checkpoint
*
* @param boolean $readable Whether the result must be human readable
* @param string $format The format to display (printf format)
* @return string|float
*/
public function getMemoryUsage($raw = false, $format = null)
{
return $raw ? $this->memory_usage : self::readableSize($this->memory_usage, $format);
}
/**
* Returns the memory peak, readable or not
*
* @param boolean $readable Whether the result must be human readable
* @param string $format The format to display (printf format)
* @return string|float
*/
public function getMemoryPeak($raw = false, $format = null)
{
$memory = memory_get_peak_usage(true);
return $raw ? $memory : self::readableSize($memory, $format);
}
/**
* Wraps a callable with start() and end() calls
*
* Additional arguments passed to this method will be passed to
* the callable.
*
* @param callable $callable
* @return mixed
*/
public function run(callable $callable)
{
$arguments = func_get_args();
array_shift($arguments);
$this->start();
$result = call_user_func_array($callable, $arguments);
$this->end();
return $result;
}
/**
* Returns a human readable memory size
*
* @param int $size
* @param string $format The format to display (printf format)
* @param int $round
* @return string
*/
public static function readableSize($size, $format = null, $round = 3)
{
$mod = 1024;
if (is_null($format)) {
$format = '%.2f%s';
}
$units = explode(' ','B Kb Mb Gb Tb');
for ($i = 0; $size > $mod; $i++) {
$size /= $mod;
}
if (0 === $i) {
$format = preg_replace('/(%.[\d]+f)/', '%d', $format);
}
return sprintf($format, round($size, $round), $units[$i]);
}
/**
* Returns a human readable elapsed time
*
* @param float $microtime
* @param string $format The format to display (printf format)
* @return string
*/
public static function readableElapsedTime($microtime, $format = null, $round = 3)
{
if (is_null($format)) {
$format = '%.3f%s';
}
if ($microtime >= 1) {
$unit = 's';
$time = round($microtime, $round);
} else {
$unit = 'ms';
$time = round($microtime*1000);
$format = preg_replace('/(%.[\d]+f)/', '%d', $format);
}
return sprintf($format, $time, $unit);
}
}
function gen_list() {
return range(1, 1000);
}
function gen_map() {
return ['A' => 0, 'B' => 1, 'C' => 2, 'D' => 3, 'E' => 4, 'F' => 5, 'G' => 6,
'H' => 7, 'I' => 8, 'J' => 9, 'K' => 10, 'L' => 11, 'M' => 12, 'N' => 13,
'O' => 14, 'P' => 15, 'Q' => 16, 'R' => 17, 'S' => 18, 'T' => 19, 'U' => 20,
'V' => 21, 'W' => 22, 'X' => 23, 'Y' => 24, 'Z' => 25];
}
function gen_string() {
return file_get_contents('data/UTF-8-demo.txt');
}
function gen_data() {
return json_decode(gen_json());
}
function gen_json() {
return file_get_contents('data/generated.json');
}
function bench_jsond_encode_list() {
echo 'jsond: ';
$data = gen_list();
$bench = new Ubench;
$bench->run(function ($_data) {
for ($i=0; $i<10000; $i++){
jsond_encode($_data);
};
}, $data);
echo microseconds($bench->getTime(true))/10000 . ' μs/op';
echo PHP_EOL;
}
function bench_json_encode_list() {
echo 'json: ';
$data = gen_list();
$bench = new Ubench;
$bench->run(function ($_data) {
for ($i=0; $i<10000; $i++){
json_encode($_data);
};
}, $data);
echo microseconds($bench->getTime(true))/10000 . ' μs/op';
echo PHP_EOL;
}
function bench_jsond_encode_map() {
echo 'jsond: ';
$data = gen_map();
$bench = new Ubench;
$bench->run(function ($_data) {
for ($i=0; $i<10000; $i++){
jsond_encode($_data);
};
}, $data);
echo microseconds($bench->getTime(true))/10000 . ' μs/op';
echo PHP_EOL;
}
function bench_json_encode_map() {
echo 'json: ';
$data = gen_map();
$bench = new Ubench;
$bench->run(function ($_data) {
for ($i=0; $i<10000; $i++){
json_encode($_data);
};
}, $data);
echo microseconds($bench->getTime(true))/10000 . ' μs/op';
echo PHP_EOL;
}
function bench_jsond_encode_string() {
echo 'jsond: ';
$data = gen_string();
$bench = new Ubench;
$bench->run(function ($_data) {
for ($i=0; $i<10000; $i++){
jsond_encode($_data);
};
}, $data);
echo microseconds($bench->getTime(true))/10000 . ' μs/op';
echo PHP_EOL;
}
function bench_json_encode_string() {
echo 'json: ';
$data = gen_string();
$bench = new Ubench;
$bench->run(function ($_data) {
for ($i=0; $i<10000; $i++){
json_encode($_data);
};
}, $data);
echo microseconds($bench->getTime(true))/10000 . ' μs/op';
echo PHP_EOL;
}
function bench_jsond_encode_data() {
echo 'jsond: ';
$data = gen_data();
$bench = new Ubench;
$bench->run(function ($_data) {
for ($i=0; $i<10000; $i++){
jsond_encode($_data);
};
}, $data);
echo microseconds($bench->getTime(true))/10000 . ' μs/op';
echo PHP_EOL;
}
function bench_json_encode_data() {
echo 'json: ';
$data = gen_data();
$bench = new Ubench;
$bench->run(function ($_data) {
for ($i=0; $i<10000; $i++){
json_encode($_data);
};
}, $data);
echo microseconds($bench->getTime(true))/10000 . ' μs/op';
echo PHP_EOL;
}
function bench_jsond_decode() {
echo 'jsond: ';
$json = gen_json();
$bench = new Ubench;
$bench->run(function ($_json) {
for ($i=0; $i<10000; $i++){
jsond_decode($_json);
};
}, $json);
echo microseconds($bench->getTime(true))/10000 . ' μs/op';
echo PHP_EOL;
}
function bench_json_decode() {
echo 'json: ';
$json = gen_json();
$bench = new Ubench;
$bench->run(function ($_json) {
for ($i=0; $i<10000; $i++){
json_decode($_json);
};
}, $json);
echo microseconds($bench->getTime(true))/10000 . ' μs/op';
echo PHP_EOL;
}
function microseconds($microtime) {
return $microtime * 1000 * 1000;
}
function main() {
echo '## EncoderBench' . PHP_EOL . PHP_EOL;
bench_jsond_encode_data();
bench_json_encode_data();
echo PHP_EOL;
echo '## EncoderBench - lists' . PHP_EOL . PHP_EOL;
bench_jsond_encode_list();
bench_json_encode_list();
echo PHP_EOL;
echo '## EncoderBench - maps' . PHP_EOL . PHP_EOL;
bench_jsond_encode_map();
bench_json_encode_map();
echo PHP_EOL;
echo '## EncoderBench - strings' . PHP_EOL . PHP_EOL;
bench_jsond_encode_string();
bench_json_encode_string();
echo PHP_EOL;
echo '## ParserBench' . PHP_EOL . PHP_EOL;
bench_jsond_decode();
bench_json_decode();
echo PHP_EOL;
}
main();
## EncoderBench
jiffy 5000 425.94 µs/op
JSX 500 4652.86 µs/op
Poison 500 4954.82 µs/op
Jazz 500 7968.03 µs/op
## EncoderBench - maps
maps (jiffy) 500000 8.67 µs/op
maps (JSX) 50000 73.57 µs/op
maps (Poison) 10000 111.05 µs/op
maps (Jazz) 10000 176.39 µs/op
## EncoderBench - strings
strings (jiffy) 20000 99.95 µs/op
strings (Poison) 10000 251.14 µs/op
strings (JSX) 5000 333.83 µs/op
strings (Jazz) 5000 436.74 µs/op
## EncoderBench - string escaping
string escaping (JSX, unsupported) 1000000000 0.01 µs/op
string escaping (jiffy) 10000 147.79 µs/op
string escaping (Poison) 1000 1342.62 µs/op
string escaping (Jazz) 1000 1664.06 µs/op
## EncoderBench - lists
lists (jiffy) 10000 191.44 µs/op
lists (Poison) 1000 1376.51 µs/op
lists (Jazz) 1000 1762.38 µs/op
lists (JSX) 1000 1813.08 µs/op
## ParserBench
jiffy 5000 635.26 µs/op
Poison 1000 1264.78 µs/op
JSX 1000 2004.61 µs/op
## ParserBench - UTF-8 unescaping
UTF-8 unescaping (jiffy) 50000 73.19 µs/op
UTF-8 unescaping (Poison) 5000 346.74 µs/op
UTF-8 unescaping (JSX) 5000 466.73 µs/op
## EncoderBench
jsond: 334.87939834595 μs/op
json: 623.18260669708 μs/op
## EncoderBench - lists
jsond: 77.932000160217 μs/op
json: 88.79919052124 μs/op
## EncoderBench - maps
jsond: 8.1763982772827 μs/op
json: 10.223197937012 μs/op
## EncoderBench - strings
jsond: 282.80711174011 μs/op
json: 313.89939785004 μs/op
## ParserBench
jsond: 1347.4879026413 μs/op
json: 2502.4626016617 μs/op
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment