2005-12-11

When perl is not quite fast enough

来源: 本站收集整理 作者:佚名 评论 0 条
 

测试

必须不引进新的 bugs
当你优化现有运行代码最重要的是不引进新的 bugs 。
使用您所有的回归/regression测试 :-)
尽可能使用您所有的一整套 regression 测试。您应该有,对不?

[这时候你们或许会不安地笑,因为我打赌只有非常少的人能写份全面的测试代码]

保留原始程序的备份
应该保留一份原始代码的拷贝。假如其他的都失败了这是您最后的凭借。试着使用版本控制系统/CSV。做一个脱机备份。检查您的备份是否可读。你得保证不能丢失它。
最后,您对于优化时是否引进了新的 bugs 的最终测试为检查优化后的版本是否与原先版本有同样的输出结果。(当然,优化版本花费更少的时间)。

What causes slowness

CPU
It's obvious that if you script hogs the CPU for 10 seconds solid, then to make it go faster you'll need to reduce the CPU demand.
RAM
A lesser cause of slowness is memory.
perl trades RAM for speed
One of the design decisions Larry made for perl was to trade memory for speed, choosing algorithms that use more memory to run faster. So perl tends to use more memory.
getting slower (relative to CPU)
CPUs keep getting faster. Memory is getting faster too. But not as quickly. So in relative terms memory is getting slower. [Larry was correct to choose to use more memory when he wrote perl5 over 10 years ago. However, in the future CPU speed will continue to diverge from RAM speed, so it might be an idea to revisit some of the CPU/RAM design trade offs in parrot]
memory like a pyramid

You can never have enough memory, and it's never fast enough.

Computer memory is like a pyramid. At the point you have the CPU and its registers, which are very small and very fast to access. Then you have 1 or more levels of cache, which is larger, close by and fast to access. Then you have main memory, which is quite large, but further away so slower to access. Then at the base you have disk acting as virtual memory, which is huge, but very slow.

Now, if your program is swapping out to disk, you'll realise, because the OS can tell you that it only took 10 seconds of CPU, but 60 seconds elapsed, so you know it spent 50 seconds waiting for disk and that's your speed problem. But if your data is big enough to fit in main RAM, but doesn't all sit in the cache, then the CPU will keep having to wait for data from main RAM. And the OS timers I described count that in the CPU time, so it may not be obvious that memory use is actually your problem.

This is the original code for the part of the Encode compiler (enc2xs) that generates the warnings on duplicate characters:

    if (exists $seen{$uch}) {

        warn sprintf("UX is XX and XX\n",

                     $val,$page,$ch,@{$seen{$uch}});

    }

    else {

        $seen{$uch} = [$page,$ch];

    }

It uses the hash %seen to remember all the Unicode characters that it has processed. The first time that it meets a character it won't be in the hash, the
共13页: 上一页 [1] [2] 3 [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] 下一页

(本文仅表明作者个人观点,不代表本站及其管理员立场.) 推荐 收藏 投稿 打印 返回 关闭
上一篇:被百度降权后,网站该怎么办?  
下一篇:SQL Server2000数据库文件损坏时如何恢复
    评论加载中…
 推荐文章
     

网站首页  -  网站地图 -   站长论坛  -  网站投稿  -    -  网站管理
Copyright © 2008 芜湖站长站 All Rights Reserved 皖ICP备07500611号