| CARVIEW |
Select Language
HTTP/2 302
server: nginx
date: Wed, 24 Dec 2025 01:47:02 GMT
content-type: text/plain; charset=utf-8
content-length: 0
x-archive-redirect-reason: found capture at 20100509020633
location: https://web.archive.org/web/20100509020633/https://github.com/ning/ub
server-timing: captures_list;dur=0.893793, exclusion.robots;dur=0.057704, exclusion.robots.policy;dur=0.042804, esindex;dur=0.013637, cdx.remote;dur=26.260297, LoadShardBlock;dur=278.237574, PetaboxLoader3.datanode;dur=180.895557, PetaboxLoader3.resolve;dur=47.142507
x-app-server: wwwb-app227-dc8
x-ts: 302
x-tr: 342
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
set-cookie: wb-p-SERVER=wwwb-app227; path=/
x-location: All
x-as: 14061
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
HTTP/2 200
server: nginx
date: Wed, 24 Dec 2025 01:47:03 GMT
content-type: text/html; charset=utf-8
x-archive-orig-server: nginx/0.7.61
x-archive-orig-date: Sun, 09 May 2010 02:06:33 GMT
x-archive-orig-connection: close
x-archive-orig-status: 200 OK
x-archive-orig-etag: "aa1ad0bae7ecd392a5abddcad7efe37e"
x-archive-orig-x-runtime: 105ms
x-archive-orig-content-length: 26162
x-archive-orig-cache-control: private, max-age=0, must-revalidate
x-archive-guessed-content-type: text/html
x-archive-guessed-charset: utf-8
memento-datetime: Sun, 09 May 2010 02:06:33 GMT
link: ; rel="original", ; rel="timemap"; type="application/link-format", ; rel="timegate"
content-security-policy: default-src 'self' 'unsafe-eval' 'unsafe-inline' data: blob: archive.org web.archive.org web-static.archive.org wayback-api.archive.org athena.archive.org analytics.archive.org pragma.archivelab.org wwwb-events.archive.org
x-archive-src: 52_15_20100509002705_crawl102-c/52_15_20100509020437_crawl101.arc.gz
server-timing: captures_list;dur=0.456529, exclusion.robots;dur=0.015040, exclusion.robots.policy;dur=0.007724, esindex;dur=0.009096, cdx.remote;dur=7.298578, LoadShardBlock;dur=1180.960454, PetaboxLoader3.datanode;dur=1098.110805, PetaboxLoader3.resolve;dur=140.697768, load_resource;dur=121.765877
x-app-server: wwwb-app227-dc8
x-ts: 200
x-tr: 1358
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
x-location: All
x-as: 14061
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
content-encoding: gzip
ning's ub at master - GitHub
ning / ub
- Source
- Commits
- Network (2)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Branch:
master
click here to add a description
click here to add a homepage
David Sklar (author)
Tue May 04 10:50:04 -0700 2010
ub /
| name | age | message | |
|---|---|---|---|
| |
.gitignore | Tue May 04 09:09:35 -0700 2010 | Initial source release [David Sklar] |
| |
LICENSE | Tue May 04 09:09:35 -0700 2010 | Initial source release [David Sklar] |
| |
README | Tue May 04 09:09:35 -0700 2010 | Initial source release [David Sklar] |
| |
b/ | Tue May 04 10:50:04 -0700 2010 | support benchmark files that contain closing tags [David Sklar] |
| |
clock/ | Tue May 04 09:09:35 -0700 2010 | Initial source release [David Sklar] |
| |
test/ | Tue May 04 09:09:35 -0700 2010 | Initial source release [David Sklar] |
| |
ub | Tue May 04 09:09:35 -0700 2010 | Initial source release [David Sklar] |
| |
ub.php | Tue May 04 10:50:04 -0700 2010 | support benchmark files that contain closing tags [David Sklar] |
README
-*-org-*-
#+TITLE: ub
* What
ub is a PHP microbenchmarking framework. Its purpose is to make it
fast and easy to write little code snippets and see how long they take
to run. This is particularly useful if there are a few potential ways
of solving a problem and you want to choose the fastest one.
* Basics
An ub microbenchmark is just a regular PHP script. It needs a few
comments in a few places to tell ub what to measure.
The most important comment is "// time". It tells ub to measure how
long it takes to execute the code that comes after the comment. For
example:
<?php
// time
array_merge(array('alice'), array('alice','bob'));
Save that code to a file called "array-merge.php" and then run:
ub array-merge.php
You'll get some output that looks like:
array-merge: mean=0.005670 median=0.005000 min=0.005000 max=0.027000 stdev=0.001417
All times are in milliseconds. By default, ub runs your code 1000
times and then reports the results across all 1000 iterations. The
"-i" command line argument changes the number of iterations.
Frequently, you need some setup code that you don't want to include in
the timing but needs to be run on each benchmark iteration
nonetheless. The ub comment that marks this kind of code is
"// init". For example:
<?php
// init
$numbers = range(0, 100);
shuffle($numbers);
// time
sort($numbers);
Each time ub executes a timing loop, it runs the range() and shuffle()
functions, turns on the clock, runs sort(), and then turns off the
clock. This ensures a potentially different array is shuffled in each
iteration, but the time required to construct the shuffled array isn't
part of the results.
When benchmarking functions or classes, you need to define the
function or class just once, not each time through the timing
loop. That's where the "// once" comment comes in. Use that to denote
code that should run just once, before the timing loop starts. For
example:
<?php
// once
function range_and_shuffle($size) {
$numbers = range(0, $size);
shuffle($numbers);
return $numbers;
}
// init
$nums = range_and_shuffle(100);
// time
sort($nums);
There are two other comments that are useful:
- "// done" marks code that is run inside each loop *after* the code
to time is run. The "// done" code does not count towards the
measured times.
- "// ignore" marks code that is ignored when benchmarking is
active. This is useful for debugging or other information you want
to print out when running the benchmark script through regular PHP
or through ub's runner mode.
Only the "// time" comment is required. The rest are optional, but if
they appear, have to be in order: once, init, time, done, ignore. You
must use the "//" comment style. (And strictly speaking, "//time" is
not required -- if you leave it out, the results will just reflect the
overhead of two successive gettimeofday() calls in PHP.)
* Options and Intracacies
** Passing Options to Benchmarks
Having to write entirely separate benchmark files for small variations
(such as the number of elements in an array of numbers to sort) is
tedious. Instead, use ub's option passing capabilities. The -x
command-line argument, which can be specified more than once, tells ub
to populate an $___opts array that will be available to the benchmark
file. Depending on how -x is used, different values show up in
$___opts. For example:
Command line: no -x arguments
$___opts structure: array()
Command line: -x asparagus
$___opts structure: array('asparagus' => true)
Command line: -x asparagus -x broccoli=green
$___opts structure: array('asparagus' => true, 'broccoli' => 'green')
Command line: -x asparagus -x broccoli=green -x broccoli=12
$___opts structure: array('asparagus' => true, 'broccoli' => array('green','12')
-x values with = in them are converted to key/value pairs (and the
values are always strings); -x values without = result in a value of
boolean true. Multiple keys result in $___opts array values which are
themselves values.
** Runner Mode
If you've created a benchmark file that uses $___opts, you've lost a
little bit of the ease of testing your benchmarking file by running it
through regular PHP -- there is no $___opts array available. ub's
"runner mode", activated with the -r command line argument helps with
this. Runner mode populates $___opts from command line arguments and
runs the benchmark file -- that's it. No iteration, no special
attention to the comments that delimit the file. After runner mode
builds $___opts, your benchmark file is run as usual.
** Multiple Benchmarks
You can supply multiple benchmark names or filenames on the
commandline to run them all in one go. Internally, ub uses a separate
PHP process for each benchmark. This prevents any collision between
classes or functions that may have the same name in separate benchmark
files.
** Clock Extension
ub uses PHP's gettimeofday() function (which uses the underlying
gettimeofday(2) system call) to obtain wall clock time before and
after the code to be timed is run. The experimental extension in the
"clock" subdirectory provides a PHP interface to the clock_gettime(3)
Linux system call. For now, it just offers the CLOCK_MONOTONIC clock,
but this can provide a higher granularity measure of elapsed time with
less overhead. The clock-gettime.[ch] files in this directory provide
OS X functions that duplicate Linux's clock_gettime(3) functionality.
