Skip to content

Commit 2e6de3d

Browse files
committed
Added examples
1 parent a4f6f93 commit 2e6de3d

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

example/hash_algos.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
require __DIR__ . '/../vendor/autoload.php';
4+
5+
use PhpBench\Pipeline\Core\PipelineBuilder;
6+
7+
$builder = PipelineBuilder::createWithDefaults()
8+
->stage('parameter/serial', [
9+
'name' => 'algo',
10+
'values' => array_slice(hash_algos(), 0, 3),
11+
])
12+
->stage('sampler/callable', [
13+
'callable' => function ($data) { hash($data['algo'], 'Hello World'); },
14+
'iterations' => 100,
15+
])
16+
->stage('aggregator/describe', [ 'group_by' => 'algo', 'describe' => 'time' ])
17+
->stage('encoder/json', [ 'pretty' => true ])
18+
->stage('console/redraw')
19+
->stage('output/stream')
20+
21+
->run();

example/http_sampler.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
require __DIR__ . '/../vendor/autoload.php';
4+
5+
use PhpBench\Pipeline\Core\PipelineBuilder;
6+
7+
$builder = PipelineBuilder::createWithDefaults();
8+
$builder->load([
9+
[ 'parameter/serial', [ 'name' => 'url', 'values' => [
10+
'https://localhost',
11+
'https://www.bbc.co.uk',
12+
]]],
13+
[ 'valve/delay', [ 'time' => 10 ] ],
14+
[ 'sampler/curl', [ 'url' => '%url%', 'concurrency' => 10, 'async' => false ] ],
15+
[ 'filter/keys', [ 'keys' => [ 'url', 'total_time', 'connect_time', 'concurrency']]],
16+
[ 'aggregator/collector', ['limit' => 2] ],
17+
[ 'encoder/json', [ 'pretty' => true ] ],
18+
'console/redraw',
19+
'output/stream',
20+
[ 'valve/timeout', [ 'time' => 10E6 ]],
21+
]);
22+
$builder->run();

0 commit comments

Comments
 (0)