0: 0000DEAD 0000BEEF
1: 80006F56 00017DDE
2: 400037AB 0002FBBC
3: A0001BD5 0005F778
4: D0000DEA 000BEEF0
...您是否使用了这种语言最棒的特性?
我相信你不会这么做。但是你是否保留您的数组已排序,这样你能使用对分检索?这很快。但是使用 hash 应该会更快。
\G和标记/gc可能会更快。 if ( /\G.../gc ) {
...
} elsif ( /\G.../gc ) {
...
} elsif ( /\G.../gc ) {pack 和 unpack undef 您是否只为了丢弃它而计算?
For example the script in the Encode module that compiles character conversion tables would print out a warning if it saw the same character twice. If you or I build perl we'll just let those build warnings scroll off the screen - we don't care - we can't do anything about it. And it turned out that keeping track of everything needed to generate those warnings was slowing things down considerably. So I added a flag to disable that code, and perl 5.8 defaults to use it, so it builds more quickly.
许多对我有益的激烈质问者/hecklers (大部分是看过讲演的 London.pm (我将 David Adler 做为 London.pm 的一分子因为他订阅了这份列表))希望我提醒各位除非你确实绝对的需要,否则真的不应该去优化。您在让您的代码更难维修,更难扩展和更易引进新的 bugs 。很可能在一开始你就在需要优化的地方做了些不该做的事。
我同意上述观点。
同样,我也不想改变幻灯片的运行顺序。There isn't a good order to try to describe things in, and some of the ideas that follow are actually more "good practice" than optimisation techniques, so possibly ought to come before the slides on finding slowness. I'll mark what I think are good habits to get into, and once you understand the techniques then I'd hope that you'd use them automatically when you first write code. That way (hopefully) your code will never be so slow that you actually want to do some of the brute force optimising I describe here.
评论加载中…
![]() |