[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Re[2]: boolean operators
- From: Nick Gammon <nick@...>
- Date: Sat, 30 Sep 2006 13:43:23 +1000
On 30/09/2006, at 4:48 AM, David Jones wrote:
Actually I think NG was suggesting an approach where the parser,
having eaten an 'x' say, changes the lexer state so that the next
'+' is tokenised as part of a number, not as the token '+'.
An interesting side-effect of the modified parser/lexer is that it is
slightly faster. Why?
Consider the case of this statement: a = -2
In standard Lua the lexer processes 4 tokens: a, =, -, 2
In the modified version we only have 3 tokens: a, =, -2
Thus we save a trip through the lexer, and probably a bit of code in
the parser as well.
My timings:
Original Lua:
$ echo 'for i = 1,1000000 do loadstring "a = -2" end' | time lua
18.63user 0.00system 0:18.63elapsed 99%CPU (0avgtext+0avgdata
0maxresident)k
0inputs+0outputs (189major+30minor)pagefaults 0swaps
Modified Lua:
$ echo 'for i = 1,1000000 do loadstring "a = -2" end' | time lua.ng
18.06user 0.00system 0:18.07elapsed 99%CPU (0avgtext+0avgdata
0maxresident)k
0inputs+0outputs (185major+30minor)pagefaults 0swaps
The modified version runs in 96% of the time taken by the original
version.
- Nick
- References:
- Re: boolean operators, Glenn Maynard
- Re: boolean operators, Rici Lake
- Re: boolean operators, Glenn Maynard
- Re: boolean operators, Rici Lake
- Re: boolean operators, Glenn Maynard
- Re: boolean operators, David Jones
- Re: boolean operators, Nick Gammon
- Re: boolean operators, David Given
- Re: boolean operators, Glenn Maynard
- Re: boolean operators, Rici Lake
- Re: boolean operators, Luiz Henrique de Figueiredo
- Re: boolean operators, Nick Gammon
- Re[2]: boolean operators, Gunnar Zötl
- Re: Re[2]: boolean operators, David Jones