Download the PHP package serhiikorniushov/micro-bench without Composer
On this page you can find all versions of the php package serhiikorniushov/micro-bench. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Please rate this library. Is it a good library?
Informations about the package micro-bench
MicroBench
MicroBench is a simple PHP tool for micro-benchmarking your code developed by Serhii Korniushov. It measures execution time, memory usage, and memory peak usage. It supports high-resolution time (hrtime) on PHP 7.3+.
Features
- Measures elapsed time (microtime and hrtime).
- Tracks memory usage and peak memory usage.
- Simple API:
start(),finish(),getReport(). - Easy to install with Composer.
- Provides human-readable time formatting.
Installation
Install MicroBench using Composer:
This command will download the MicroBench library and its dependencies into your project's vendor directory.
Usage
Here's a basic example of how to use MicroBench:
Explanation:
- Include Autoloader:
require_once __DIR__ . '/vendor/autoload.php';loads the Composer-generated autoloader, making the MicroBench class available. - Create Instance:
$bench = new MicroBench();creates a new MicroBench object. - Start Benchmark:
$bench->start();starts the timer and records initial memory usage. It throws aRuntimeExceptionif called when a benchmark is already running or has finished. - Code to Benchmark: This is the section where you place the code you want to test.
- Finish Benchmark:
$bench->finish();stops the timer and records final memory usage. It throws aRuntimeExceptionif called beforestart()or if called a second time. - Get Report:
$report = $bench->getReport();retrieves a detailed report as an associative array. - Output Results: The example shows how to access specific values from the report, such as elapsed time and memory usage.
getElapsedMicroTimeReadable()provides a nicely formatted time string.
API Reference
start(): Starts the benchmark.finish(): Finishes the benchmark.getReport(): Returns a detailed report array.isStarted(): Checks if the benchmark has been started.isFinished(): Checks if the benchmark has been finished.getElapsedMicroTime(): Returns the elapsed time in seconds (float).getElapsedMicroTimeReadable(): Returns the elapsed time in a human-readable format (e.g., "100 ms", "1 s").formatMicroTimeDiff(float $timeDiff): (Static) Formats a time difference (in seconds) into a human-readable string.getStartMicroTime(): Returns the starting microtime.getStartMemoryUsage(): Returns the starting memory usage.getStartMemoryUsageReal(): Returns the starting real memory usage.getFinishMicroTime(): Returns the finishing microtime.getFinishMemoryUsage(): Returns the finishing memory usage.getFinishMemoryUsageReal(): Returns the finishing real memory usage.getStartMemoryPeakUsage(): Returns the starting memory peak usage.getStartMemoryPeakUsageReal(): Returns the starting real memory peak usage.getFinishMemoryPeakUsage(): Returns the finishing memory peak usage.getFinishMemoryPeakUsageReal(): Returns the finishing real memory peak usage.getStartHrTime(): Returns the starting hrtime (PHP 7.3+).getFinishHrTime(): Returns the finishing hrtime (PHP 7.3+).
All versions of micro-bench with dependencies
PHP Build Version
Package Version
Requires
php Version
^5.4 || ^5.5 || ^5.6 || ^7.0 || ^7.1 || ^7.2 || ^7.3 || ^7.4 || ^8.0 || ^8.1 || ^8.2 || ^8.3 || 8.4
The package serhiikorniushov/micro-bench contains the following files
Loading the files please wait ...