Skip to content

Instantly share code, notes, and snippets.

@dgmike
Created April 25, 2010 18:12
Show Gist options
  • Save dgmike/378591 to your computer and use it in GitHub Desktop.
Save dgmike/378591 to your computer and use it in GitHub Desktop.
Benchmark em PHP - try vs reescrita de metodos
teste1
Tempo: 0.093338966369629
Tempo: 0.083599090576172
Tempo: 0.092911958694458
Tempo: 0.084725856781006
Tempo: 0.089320182800293
Tempo: 0.082650899887085
Tempo: 0.08252215385437
Tempo: 0.092643976211548
Tempo: 0.10191297531128
Tempo: 0.09998607635498
teste2
Tempo: 0.14276003837585
Tempo: 0.12426400184631
Tempo: 0.13365197181702
Tempo: 0.13380217552185
Tempo: 0.1347861289978
Tempo: 0.13035988807678
Tempo: 0.12103509902954
Tempo: 0.11880016326904
Tempo: 0.12391209602356
Tempo: 0.12419199943542
#!/bin/bash
reset
echo "teste1"
let "i=10"
while [ $i -gt 0 ]; do
let "i=$i-1"
php teste1.php
done
echo "teste2"
let "i=10"
while [ $i -gt 0 ]; do
let "i=$i-1"
php teste2.php
done
echo
<?php
class Teste {
public function __call($method, $args)
{
if (!method_exists(array($this, $method))) {
throw new Exception('Erro');
}
}
static public function __callStatic($name, $args)
{
$obj = new self();
if (!method_exists(array($obj, $name))) {
throw new Exception('Erro');
}
}
}
error_reporting(0);
$t = microtime(true);
while ($i<1000) {
try { Teste::animal(); } catch(Exception $e) {}
++$i;
}
print "Tempo: ".(microtime(true)-$t)."\n";
<?php
class Teste {
public function __call($method, $args)
{
if (!method_exists($method)) {
throw new Exception('Erro');
}
}
static public function __callStatic($name, $args)
{
$obj = new self();
$obj->$name();
}
}
error_reporting(0);
$t = microtime(true);
while ($i<1000) {
try { Teste::animal(); } catch (Exception $e) {}
++$i;
}
print "Tempo: ".(microtime(true)-$t)."\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment