Profilo di agentzhHuman & MachineFotoBlogElenchiAltro ![]() | Guida |
|
27 giugno The first yahoo.cn feature that is powered by OpenRestySee the company blog post here for details: http://ysearchblog.cn/2008/06/post_120.html especially my comment at the bottom of the web page. Have fun! 24 giugno 基于 Perl 的 Firefox 插件开发框架 XUL::App 发布我很高兴地宣布 XUL::App 已经发布到了 CPAN: http://search.cpan.org/perldoc?XUL::App XUL::App 是 Yahoo! 4E team 开发的基于 Perl 的 Firefox 插件的开发框架,最初是为了简化搜索引擎平行比较工具 SearchAll 插件的开发工作而设计的。随后,我们又利用 XUL::App 框架开发了一款能从 Google Reader 中导出 RSS 数据项的小插件 ExportReader。有趣的是,ExportReader 总共只手写了约 10 行 Perl 代码和 20 行 JavaScript 代码。最近,我又花了几个小时的时间,把原来我们 FE 开发的"雅虎收藏+"插件移植到了 XUL::App 框架中,从而使得调试和打包工作都只是简单的一条命令。(引用晓栓同学的话说,就是"今天下午看Agent 调程序,那是相当的酷:)") 我在 4E team 内部作的 XUL::App 演讲所使用的幻灯片介绍了 XUL::App 的几个重要特性: http://agentzh.org/misc/slides/xulapp.pdf 熟悉 Perl 酷炫的 Jifty 框架的朋友会发现 XUL::App 就是 XUL 星球上的 Jifty :) XUL::App 是一个我们领导的开源项目,目前仍处于比较早期的阶段。我们目前需要一个完整的测试集,以及更多的文档(特别是更多的教程)。如果你有兴趣参与开发和自动化测试工作的话,请发送邮件给我们(agentzh@yahoo.cn),我们很乐意递送 Subversion 提交权限 :) -agentzh 20 giugno UML::Class::Simple 0.10 releasedI've just uploaded UML::Class::Simple 0.10 to CPAN with the highlight of the XMI format support. It will appear on the CPAN mirror near you in the next few hours. Thanks Maxim Zenin for contributing this feature :) A Japanese user was requesting this in his blog as well. If you're a XMI fanboy, feel free to try it out. 12 giugno Optimizing Haskell code: from String to ByteString Haskell's built-in strings are notoriously slow. The String type in Haskell is [Char] per se. I was told that there was a much faster alternative provided by the bytestring (or fps) library by the Pugs blog a few years ago. (Thanks Audrey!) However, it took me a while to figure out how to use it in my code. Eventually I found that All I needed were in the Data.ByteString.Char8 module rather than Data.ByteString. (Thanks Hoogle!) According to the document, it's recommended to import the module this way import qualified Data.ByteString.Char8 as B to prevent name clashing with Prelude. Converting String to B.ByteString is straightforward: B.pack "Hello, world" where "Hello, world" is of type String. Or in the other direction: B.unpack s where s is of type B.ByteString. Concatenating several bytestrings together can be done by the B.concat function: B.concat [B.pack "hello", B.pack ", ", B.pack "world"] or just use B.append for joining two bytestrings for handy: (B.pack "hello, ") `B.append` (B.pack "world") Personally I like to define a ~~ operator for a bytestring version of ++ this way: (~~) :: B.ByteString -> B.ByteString -> B.ByteString (~~) = B.append and then I can simply write: B.pack "hello, " ~~ B.pack "world" Bytestring versions for most of the functions in Prelude are also provided. For instance, printing out a bytestring to stdout can be done directly by B.putStrLn bs -- bs is of type B.ByteString rather than the cumbosome and also slow putStrLn $ B.unpack bs As bytestring's documentation points out, converting back and forth between bytestrings and Haskell's built-in strings could become the bottleneck of the program, especially when the source comes with lots of string literals like "Hello, world" shown above. Wouldn't it be nice if string literals get automatically interpreted by the GHC compiler to bytestrings without going through a B.pack? Fortunately, with bytestring 0.9.0.4 (or better) and GHC 6.8.1 (or better), it is possible to do that via the GHC option -XOverloadedStrings. So now we can write literals without mudding around with B.pack: B.concat ["hello", ", ", "world"] or "hello, " ~~ "world" Perfect! :D Note that, as of this writing, the bytestring library in Ubuntu 8.04's debian repository is not new enough to support this. So ubuntu users have to install the latest version from HackageDB like this: $ wget http://hackage.haskell.org/packages/archive/bytestring/0.9.1.0/bytestring-0.9.1.0.tar.gz $ tar -xzf bytestring-0.9.1.0.tar.gz $ cd bytestring-0.9.1.0/ $ runghc Setup.lhs configure -p $ runghc Setup.lhs build $ sudo runghc Setup.lhs install By switching to B.ByteString in my code emitters for the minisql compiler mentioned in the previous blog post, the execution time dramatically reduced from 7.0 sec to 2.3 sec in my stress tests generated by the Perl module Parse::RandGen::Regexp. This is really an amazing improvement :) Furthermore, my UTF-8 regression tests kept passing as well. In the next journal I'll present another optimization trick that further reduced the running time from 2.3 sec to 1.0 sec. (Well, it has nothing to do with -O2 BTW, and I turned on -O2 from the very beginning already ;)) |
|
|