Skip to content

Commit 28e7477

Browse files
committed
test: Add option to pass a file to bench.php for ad-hoc micro benching
Change-Id: If86b1806e6f56b1fd3509c509bb73812d060564e
1 parent eadfdc6 commit 28e7477

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

test/CSSJanusBenchmark.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
<?php
22

33
class CSSJanusBenchmark {
4+
private $fixtures;
5+
6+
/**
7+
* @param null|array<string,string> $fixtures Map from label to input CSS
8+
*/
9+
public function __construct(array $fixtures = null) {
10+
$this->fixtures = $fixtures ?? self::getFixtures();
11+
}
412

513
public function run() {
6-
foreach (self::getFixtures() as $name => $data) {
14+
foreach ($this->fixtures as $name => $data) {
715
$iterations = 10_000;
816
$total = 0;
917
$max = -INF;

test/bench.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,11 @@
33
require_once __DIR__ . '/../vendor/autoload.php';
44
require_once __DIR__ . '/CSSJanusBenchmark.php';
55

6-
( new CSSJanusBenchmark )->run();
6+
$fixtures = null;
7+
if (isset($argv[1])) {
8+
$name = basename($argv[1]);
9+
$data = file_get_contents($argv[1]);
10+
$fixtures = [ $name => $data ];
11+
}
12+
13+
( new CSSJanusBenchmark($fixtures) )->run();

0 commit comments

Comments
 (0)