Skip to content

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Oct 26, 2025

this strtolower call is showing up in blackfire profiles

grafik

because we invoke it millions of times


local benchmarks tells me strcasecmp is 2x faster

fec) ✗ hyperfine 'php perf.php'
Benchmark 1: php perf.php
  Time (mean ± σ):     403.3 ms ±   8.6 ms    [User: 392.5 ms, System: 8.0 ms]
  Range (min … max):   385.6 ms … 414.7 ms    10 runs
 
➜  phpstan-src git:(infec) ✗ hyperfine 'php perf.php'
Benchmark 1: php perf.php
  Time (mean ± σ):     195.8 ms ±  10.1 ms    [User: 186.0 ms, System: 7.2 ms]
  Range (min … max):   183.3 ms … 219.4 ms    16 runs

running

<?php

function generateRandomString($length = 10) {
	return substr(str_shuffle(str_repeat($x='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil($length/strlen($x)) )),1,$length);
}

$var1 = generateRandomString();
$var2 = generateRandomString();

$x = false;
for ($i = 0; $i < 10_000_000; $i++) {
	if (strcasecmp($var1, $var2) === 0) {
	//if (strtolower($var1) === strtolower($var2)) {
		$x = true;
	}
}

working my way thru things showing up in profiles of phpstan/build-infection#11 (comment)

@ondrejmirtes ondrejmirtes merged commit 326d512 into phpstan:2.1.x Oct 26, 2025
538 of 552 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

@staabm staabm deleted the perf branch October 26, 2025 10:50
@VincentLanglet
Copy link
Contributor

There is ~70 occurences of strtolower\(.*\) === ; should the same be done at other places @staabm ?

@staabm
Copy link
Contributor Author

staabm commented Oct 26, 2025

Other places did not show up in my profilling yet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants