Re: Message trees can be fast
- From: "bartc" <bartc@xxxxxxxxxx>
- Date: Tue, 10 Nov 2009 00:03:55 GMT
"Mike Austin" <mike@xxxxxxxxxxxxxxxxxxxxxx> wrote in message news:D6qdnQ3NHuiRSGjXnZ2dnUVZ_qSdnZ2d@xxxxxxxxxxxxxxx
It's been said that interpreting a message tree will likely be much slower than interpreting bytecode. While developing Impulse, I wanted to see how far I could push message trees, and recent optimization have proven fruitful. In this microbenchmark (I know, I know), it takes under 5 seconds to iterate 3,600,000 times while performing a simple coordinate rotation:
rotations = 360 * 10000
x0 = 10
y0 = 0
(1..rotations) each: a ->
a = a * (PI / 180)
x1 = (x0 * a cos) - (y0 * a sin)
y1 = (x0 * a sin) + (y0 * a cos)
end
/impulse-0.5.3/bench$ time impulse rotate.im
real 0m4.893s
user 0m4.832s
sys 0m0.012s
So I'm happy :) This is on par with Ruby 1.9 and faster than Python 3, granted
Being faster than Ruby or Python is not difficult...
However I think this test might be dominated by the time taken for the sin and cos functions (especially if they are each executed twice, if that optimisation is not done, and maybe if they have trouble dealing with very large angles...)
I don't know how fast your machine is, but on mine Python took some 9 seconds, while a C version using gcc took between 1 and 2 seconds (optimised/not optimised).
I think the fastest possible speed must be with some form of bytecode (if you stay with interpretation), but if you want to use parse trees, I don't think it will slow things down so much, (maybe 2-4 times?), but the performance depends on lots of other factors.
there are some optimization which I'll have to evaluate in a larger scale program. Some of the optimizations include minimal dynamic allocation, specialized math messages and inlining all core functions. Also, message chains, such as "a sin abs", are arrays instead of trees.
The only thing left I can optimize is the lookup, which currently uses a std::map.
What's the lookup for?
--
Bartc
.
- Follow-Ups:
- Re: Message trees can be fast
- From: Mike Austin
- Re: Message trees can be fast
- References:
- Message trees can be fast
- From: Mike Austin
- Message trees can be fast
- Prev by Date: Re: Message trees can be fast
- Next by Date: Re: Message trees can be fast
- Previous by thread: Re: Message trees can be fast
- Next by thread: Re: Message trees can be fast
- Index(es):
Relevant Pages
|