Python在获取索引位置方面比PHP慢

2024-09-28 22:22:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我惊讶地发现Python在获取索引位置上比PHP慢。有没有方法可以提高Python的性能?在

例如:

用PHP计算:18.169965982437

<?php
$time_start = microtime(true);
$needle = file_get_contents("needle.wav", false, null, 46);

foreach(range(0, 10000) as $num) {
   $haystack = file_get_contents("haystack.wav");
   $match = strpos($haystack,$needle);
}

$time_end = microtime(true);

$finishTime = $time_end - $time_start;
echo $finishTime;
?>

在Python中,它需要:23.6319999695

^{pr2}$

Tags: 方法truegettimecontents性能startfile