exists is false, so the else block executes. It stores an arrayref containing the code page and character number in that page. That's three things per character, and there are a lot of characters in Chinese.If it ever sees the same Unicode character again, it prints a warning message. The warning message is just a string, and this is the only place that uses the data in %seen. So I changed the code - I pre-formatted that bit of the error message, and stored a single scalar rather than the three:
if (exists $seen{$uch}) {
warn sprintf("UX is XX and X\n",
$val,$page,$ch,$seen{$uch});
}
else {
$seen{$uch} = $page << 8 | $ch;
}That reduced the memory usage by a third, and it runs more quickly.
How do you make things faster? Well, this is something of a black art, down to trial and error. I'll expand on aspects of these 4 points in the next slides.
By having commented out slower code near the faster code you can look back and get ideas for other places you might optimise in the same way.
下面是一些我认为有用的习惯,所以您应当将它们运用到日常程序中。
AutoSplit 与 AutoLoader 一个可能的问题是使用 AutoLoader 让子程序带来调试混乱。当处于测试状态,您能通过在自动加载子程序前添加注释 __END__ 来使 AutoLoader 失效。如此一来,它们就普通地被加载,编译和测试了。
... 1; # While debugging, disable AutoLoader like this: # __END__ ...
当然,为了使 use 正常,您还得在加载程序段的后面另添加 1; 和可能要另一个 __END__
评论加载中…
![]() |