forrest79 / phpgsql

Simple and fast PHP database library for PostgreSQL with auto converting DB types to PHP and fluent interface for SQL query writing.
Other
11 stars 3 forks source link

Using intval,floatval instead of anonymous functions #5

Closed klapuch closed 5 years ago

klapuch commented 5 years ago

I thinks it's more readable + times are better:

<?php declare(strict_types=1);

$array = ['10', '20', '99', 5, 6, 8];

$s = microtime(true);

for ($i = 0; $i < 1000000; ++$i) {
    array_map('intval', $array);
}

var_dump(microtime(true) - $s);

$s = microtime(true);

for ($i = 0; $i < 1000000; ++$i) {
    array_map(static function ($value): int {
        return (int) $value;
    }, $array);
}

var_dump(microtime(true) - $s);

Times:

float(0.23932003974915)
float(0.40849304199219)
forrest79 commented 5 years ago

Thanks 👍