nafigator / php-bench Goto Github PK
View Code? Open in Web Editor NEW:alarm_clock: Tools for benchmark PHP algorithms.
License: BSD 3-Clause "New" or "Revised" License
:alarm_clock: Tools for benchmark PHP algorithms.
License: BSD 3-Clause "New" or "Revised" License
Supress notices about using mysql_* functions.
Add to MysqlVsMysqliVsPdoRead test unbuffered query case.
Check out performance of SplFixedArrays vs generic arrays.
Add missing descriptions to tests
Select concrete column instead all (*) in sql-query.
Add screen with yellow and red results.
Fix readme headers markup.
Test how generators affect on performance.
Check for performance of phar-autoloader.
If test results within 10% colorize them by yellow.
Compare mysql functions for write performance
I received a link to this repo from a colleague as an evidence using (int)
(type cast) is faster than using intval(...)
.
I ran the scripts with only this addition:
$ diff test test-example
64d63
< $application->setRepeats($argv[2] ?? 10000);
So I could run tests with an arbitrary repeat number.
Running the included IntvalVsTypeCast
I got these results:
$ ./test IntvalVsTypeCast 1000000
# omitted progress bars for brevity
Test name Repeats Result Performance
(int) 1000000 0.115288 sec +0.00%
intval() 1000000 0.120689 sec -4.68%
Which seems to validate my colleague assumption.
But then I created a new class and just inverted the tests (code at end) and got inverted results:
$ ./test TypeCastVsIntval 1000000
# omitted progress bars for brevity
Test name Repeats Result Performance
intval() 1000000 0.137540 sec +0.00%
(int) 1000000 0.143018 sec -3.98%
Of course the difference is not big enough, and convinced this colleague to stop complaining on me using intval()
instead of (int)
(also from the progress bar output it seems intval()
uses slightly less memory, but it is very unlikely one would need to run a million integer conversion in a row), but I thought it would be a good idea to report.
I didn't run other tests to check if this issue holds true for all of them. And of course, I ran both tests several times before posting this issue, and the results don't vary very much.
My system reference:
$ neofetch --backend off
rodrigo@rodrigo-pc
------------------
OS: KDE neon User Edition 5.21 x86_64
Kernel: 5.4.0-73-generic
Uptime: 2 hours, 32 mins
Packages: 2694 (dpkg), 15 (flatpak), 10 (snap)
Shell: bash 5.0.17
Resolution: 1920x1080, 1920x1080, 1920x1080, 1920x1080
DE: Plasma
WM: KWin
WM Theme: plastik
Theme: Breeze Light [Plasma], Breeze [GTK2/3]
Icons: breeze [Plasma], breeze [GTK2/3]
Terminal: konsole
Terminal Font: Ubuntu Mono 14
CPU: Intel i9-9900 (16) @ 3.100GHz
GPU: NVIDIA GeForce GTX 1650
Memory: 6437MiB / 64264MiB
PHP version:
$ php -v
PHP 7.4.18 (cli) (built: May 3 2021 11:27:06) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.18, Copyright (c), by Zend Technologies
Added class:
<?php
/**
* What is faster typecasting or function intval()
*
* @file IntvalVsTypeCast.php
*
* PHP version 5.4+
*
* @author Alexander Yancharuk <alex at itvault dot info>
* @date Thu Apr 03 14:39:45 2014
* @license The BSD 3-Clause License
* <https://tldrlegal.com/license/bsd-3-clause-license-(revised)>
*/
namespace Tests;
use Application\TestApplication;
use Veles\Tools\CliProgressBar;
use Veles\Tools\Timer;
/**
* Class TypeCastVsIntval
*
* @author Alexander Yancharuk <alex at itvault dot info>
*/
class TypeCastVsIntval extends TestApplication
{
protected $repeats = 10000;
public function run()
{
$repeats = $this->getRepeats();
$bar = new CliProgressBar($repeats);
for ($i = 1; $i <= $repeats; ++$i) {
Timer::start();
intval(5.55);
Timer::stop();
$bar->update($i);
}
$this->addResult('intval()', Timer::get());
Timer::reset();
$bar = new CliProgressBar($repeats);
for ($i = 1; $i <= $repeats; ++$i) {
Timer::start();
(int) 5.55;
Timer::stop();
$bar->update($i);
}
$this->addResult('(int)', Timer::get());
}
}
Note: I just inverted the tests from IntvalVsTypeCast
, although in both classes the tests don't match the class name order.
If I can provide any other info to help debug it, please let me know.
Check different algorithms that removes spaces out of string.
Write a test for comparison data processing with iterators and simple foreach.
Link: http://seyferseed.ru/ru/php/uskorenie-zaprosov-v-bazu-dannyh-s-pdo-i-iteratorami.html
Add to MysqlVsMysqliVsPdoRead test non-object mysqli case.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.