- ベストアンサー
※ ChatGPTを利用し、要約された質問です(原文:$_ と local($_))
Why is b1 faster than a1 in benchmarking?
このQ&Aのポイント
- In the benchmarking of a1 and b2, it was found that b1 is slightly faster than a1, even when the positions of the function groups a and b are reversed. The benchmarking was performed by counting 10,000,000 times.
- The local operator is used to temporarily change the values of special symbols such as $_. In the past, it was mentioned in the 'camel book' that this extra work of using local would take more time. However, the benchmarking results show that b1 is faster.
- The reason behind this unexpected result lies in the internal workings of the local operator and the specific example chosen for benchmarking.
- みんなの回答 (1)
- 専門家の回答
質問者が選んだベストアンサー
($_) = @_; の左側は、一時的なリストを作るために余計に時間が掛かるのではないかと思います。
お礼
ご指摘いただいた箇所を、 「$_ = $_[0]」と直した所、無事localを使わない方が速くなりました。これですっきりしました、ご回答ありがとうございます。