Skip to content

Commit

Permalink
add benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
flotzilla committed Mar 27, 2020
1 parent 5a26453 commit dd3f338
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
44 changes: 44 additions & 0 deletions benchmarks/LoggerBench.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php


use flotzilla\Logger\Channel\Channel;
use flotzilla\Logger\Formatter\PsrFormatter;
use flotzilla\Logger\Formatter\SimpleLineFormatter;
use flotzilla\Logger\Handler\FileHandler;
use flotzilla\Logger\Logger;

class LoggerBench
{
/**
* @Revs(5)
* @Iterations(10)
* @throws \flotzilla\Logger\Exception\InvalidConfigurationException
*/
public function benchLog()
{
$channels = [
new Channel('test', [
new FileHandler('test-simple-line', 'tmp', new SimpleLineFormatter()),
new FileHandler('test-psr-formatter', 'tmp', new PsrFormatter())
])
];

$logger = new Logger($channels);
$logger->info('test message');
}

public function benchInsert()
{
$channels = [
new Channel('test', [
new FileHandler('test-simple-line', 'tmp', new SimpleLineFormatter()),
new FileHandler('test-psr-formatter', 'tmp', new PsrFormatter())
])
];

$logger = new Logger($channels);
foreach (range(0, 100000) as $iteration) {
$logger->info('test message' . rand($iteration));
}
}
}
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
},
"require-dev": {
"phpunit/phpunit": "^7",
"phpstan/phpstan": "^0.12.14"
"phpstan/phpstan": "^0.12.14",
"phpbench/phpbench": "@dev"
},
"license": "MIT",
"authors": [
Expand All @@ -37,6 +38,9 @@
],
"stan": [
"vendor/bin/phpstan analyse -l 4 -c phpstan.neon.dist src"
],
"bench": [
"vendor/bin/phpbench run benchmarks --report=aggregate"
]
}
}
3 changes: 3 additions & 0 deletions phpbench.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"bootstrap": "vendor/autoload.php"
}

0 comments on commit dd3f338

Please sign in to comment.