<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Erlang非业余研究 &#187; leex</title>
	<atom:link href="http://blog.yufeng.info/archives/tag/leex/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.yufeng.info</link>
	<description>Erlang系统深度探索和应用</description>
	<lastBuildDate>Tue, 17 Jan 2012 06:05:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>leex文法分析的效率</title>
		<link>http://blog.yufeng.info/archives/89</link>
		<comments>http://blog.yufeng.info/archives/89#comments</comments>
		<pubDate>Mon, 12 Oct 2009 13:00:13 +0000</pubDate>
		<dc:creator>Yu Feng</dc:creator>
				<category><![CDATA[Erlang探索]]></category>
		<category><![CDATA[erl_scan]]></category>
		<category><![CDATA[leex]]></category>

		<guid isPermaLink="false">http://blog.yufeng.info/?p=89</guid>
		<description><![CDATA[原创文章，转载请注明： 转载自Erlang非业余研究 本文链接地址: leex文法分析的效率 R13B新添加的leex相当于c的lex， 在做文法分析非常方便，但是效率如何呢？ leex的example里面带了个erlang_scan和erlang标准的发布版的erl_scan兼容，所以我们来对比测试下效率。 注意用R13B03，因为R13B02的erlc漏掉了编译xrl格式。 以下是实验： %% 这个版本稍微慢点 结论是： leex产生的代码和手写的效率几乎差不多。 Post Footer automatically generated by wp-posturl plugin for wordpress.]]></description>
			<content:encoded><![CDATA[<div style="margin-top: 15px; font-style: italic">
<p><strong>原创文章，转载请注明：</strong> 转载自<a href="http://blog.yufeng.info/">Erlang非业余研究</a></p>
<p><strong>本文链接地址:</strong> <a href="http://blog.yufeng.info/archives/89">leex文法分析的效率</a></p>
</div>
<p>R13B新添加的leex相当于c的lex， 在做文法分析非常方便，但是效率如何呢？ leex的example里面带了个erlang_scan和erlang标准的发布版的erl_scan兼容，所以我们来对比测试下效率。</p>
<p>注意用R13B03，因为R13B02的erlc漏掉了编译xrl格式。</p>
<p>以下是实验：</p>
<pre class="brush: bash; title: ; notranslate">
root@nd-desktop:~# git clone git://github.com/rvirding/leex.git
root@nd-desktop:~# cd leex/examples/
root@nd-desktop:~/leex/examples# cat test_scan.erl
</pre>
<pre class="brush: erlang; title: ; notranslate">
-module(test_scan).
-export([start/1]).
start([A])-&gt;
    {ok, F} = file:open(atom_to_list(?MODULE)++&quot;.erl&quot;, [read]),
    {ok, S} = file:read(F, 9999999),
    file:close(F),
    N = list_to_integer(A),
    test(N, fun erlang_scan:string/1, S, &quot;erlang_scan&quot;),
    test(N, fun erl_scan:string/1, S, &quot;erl_scan&quot;),
    ok.

test(N, F, S, Ts)-&gt;
    Start = erlang:now(),
    dotimes(N, fun (_) -&gt;
                       F(S)
               end),
    io:format(&quot;~s run ~w ms~n&quot;, [Ts,round(timer:now_diff(now(), Start) /1000)]).

dotimes(0, _) -&gt; done;
dotimes(N, F) -&gt;
    F(N),
    dotimes(N - 1, F).
</pre>
<pre class="brush: bash; title: ; notranslate">
root@nd-desktop:~/leex/examples# erlc erlang_scan.xrl
root@nd-desktop:~/leex/examples# ls *.erl
erlang_scan.erl  test_scan.erl
root@nd-desktop:~/leex/examples# erlc *.erl
root@nd-desktop:~/leex/examples# erl -noshell -run test_scan start 10000 -s erlang halt
erlang_scan run 2208 ms
erl_scan run 1181 ms
</pre>
<p>%% 这个版本稍微慢点</p>
<pre class="brush: bash; title: ; notranslate">
root@nd-desktop:~/leex/examples# erlc +native *.erl
root@nd-desktop:~/leex/examples# erl -noshell -run test_scan start 10000 -s erlang halt
erlang_scan run 1292 ms
erl_scan run 1238 ms
</pre>
<p>结论是： leex产生的代码和手写的效率几乎差不多。</p>
<div style="margin-top: 0; margin-bottom: 15px; color: #888888; font-size: 80%; font-style: italic">
<p>Post Footer automatically generated by <a href="http://easwy.com/blog/wordpress/wp-posturl/" style="color: #8888FF; text-decoration: underline;">wp-posturl plugin</a> for wordpress.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.yufeng.info/archives/89/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

