PHP 哪个更快:dechex() 或 sprintf("%x")?

What is faster in PHP: dechex() or sprintf("%x")?

将数字转换为 PHP 中的十六进制表示形式的最快方法是什么:dechex($number)sprintf("%x",$number)

给你... dechex 快了一个微不足道的数字
0.0042848587036133
0.0037119388580322

<?php

$numbers = [];

for ($i = 1; $i < 10000; $i++) {
    $numbers[] = random_int(1, 10000);
}

$start = microtime(true);
foreach ($numbers as $number) {
    $test = sprintf("%x",$number);
}

echo microtime(true) - $start . PHP_EOL;

$start = microtime(true);
foreach ($numbers as $number) {
    $test = dechex($number);
}

echo microtime(true) - $start . PHP_EOL;