Re: Message trees can be fast




"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


.



Relevant Pages

  • Re: Message trees can be fast
    ... without having to resort to bytecode. ... you stay with interpretation), but if you want to use parse trees, I don't ... with a highly dynamic language. ... it's possible to do much more optimization. ...
    (comp.lang.misc)
  • Message trees can be fast
    ... 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. ... So I'm happy:) This is on par with Ruby 1.9 and faster than Python 3, granted there are some optimization which I'll have to evaluate in a larger scale program. ...
    (comp.lang.misc)