Skip to content

Instantly share code, notes, and snippets.

@bwg
bwg / hashtest
Created July 10, 2014 04:58
md5 vs. sha1 vs. crc32
PHP Version 5.4.30
--------------------------------------------------
Testing 0 char string over 100,000 iterations:
md5 113.2709980011 ms
sha1 117.16985702515 ms
crc32 78.847885131836 ms
--------------------------------------------------
Testing 1 char string over 100,000 iterations:
@bwg
bwg / noticetest
Last active August 29, 2015 14:03
is checking an array_key faster than disabling E_NOTICE
PHP Version 5.4.30
-------------------------------------------------------
Testing 10 item array over 100,000 iterations:
isset 18.280982971191
array_key_exists 96.060037612915
^E_NOTICE 71.103811264038
-------------------------------------------------------
Testing 100 item array over 100,000 iterations:
@bwg
bwg / ctortest.php
Last active August 29, 2015 14:11
comparing subclasses that call parent constructors vs. cloning empty object
<?php
$iterations = 100000;
class zero {
public static function one() {
static $empties = [];
$empty = &$empties[static::class];
@bwg
bwg / arraykeytest.php
Last active August 29, 2015 14:13
array_key_exists vs. isset
<?php
$iterations = 100000;
$value = [
'one' => 1,
'two' => 2,
'three' => 3,
];