1. Go to this page and download the library: Download n0zzy/phpbenchmark library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
n0zzy / phpbenchmark example snippets
#!/usr/bin/php
ark\Attributes\Benchmark;
use N0zzy\PhpBenchmark\Attributes\BenchmarkMethod;
use N0zzy\PhpBenchmark\PhpBenchmark;
use N0zzy\PhpBenchmark\PhpBenchmarkSettings;
use N0zzy\PhpBenchmark\Services\OutputEnum;
use N0zzy\PhpBenchmark\Services\MemoryEnum;
#[PhpBenchmarkSettings(settings: [
'output' => OutputEnum::Html,
'memory' => MemoryEnum::MEDIUM,
'gc' => false
])]
class Setting {}
class A {
#[Benchmark(count: 100)]
#[BenchmarkMethod([
'class' => A::class,
'method' => 'a'
])]
private function a($class, $method)
{
static $a = 0;
$a++;
$b = $class . '::' . $method;
}
}
new PhpBenchmark(Setting::class);
#!/usr/bin/php
ark\Attributes\Benchmark;
use N0zzy\PhpBenchmark\Attributes\BenchmarkMemory;
use N0zzy\PhpBenchmark\Attributes\BenchmarkMethod;
use N0zzy\PhpBenchmark\PhpBenchmark;
#[Benchmark( count: 10 )]
#[BenchmarkMemory( limit: 500 )]
class BenchmarkTest
{
private string $a = "";
private int $b = 0;
#[Benchmark(count: 100)]
public function test1(): void
{
$this->b = rand(1, 1000);
$this->a = str_repeat( 'a', $this->b );
}
#[Benchmark(count: 100)]
public function test2(): void
{
$this->b = rand(1, 1000);
$this->a = str_repeat( 'a', $this->b );
}
}
new PhpBenchmark(
BenchmarkTest::class
);
#!/usr/bin/php
ark\Attributes\Benchmark;
use N0zzy\PhpBenchmark\Attributes\BenchmarkGC;
use N0zzy\PhpBenchmark\Attributes\BenchmarkMemory;
use N0zzy\PhpBenchmark\Attributes\BenchmarkMethod;
use N0zzy\PhpBenchmark\PhpBenchmark;
class A {
#[Benchmark(count: 10)]
#[BenchmarkMethod([
'class' => A::class,
'method' => 'a'
])]
private function a($class, $method)
{
static $a = 0;
$a++;
$b = $class . '::' . $method;
}
}
new PhpBenchmark();
text
php your_php_script_benchmark
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.