internal float handling

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: imaqine, 99jonathan, roger

User avatar
leJOS Team Member
Posts: 305
Joined: Wed Dec 05, 2007 1:27 am
Location: New Mexico, USA

internal float handling

Postby kirkpthompson » Sat Aug 29, 2009 4:40 pm

Hi all. Question is: In LeJOS implementation, how do float calcs compare to int calcs (+-/*) in terms of speed?

If i were to use scaled integers for some calcs v.s. floats, is there a speed payoff in the VM?

Leg Godt!

User avatar
leJOS Team Member
Posts: 5972
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Postby gloomyandy » Sat Aug 29, 2009 9:59 pm

Hi Kirk,
Here are some simple benchmark results:

Code: Select all

200000 intv add: 564 ms  354609/sec
200000 intv sub: 563 ms  355239/sec
200000 intv mul: 595 ms  336134/sec
200000 intv div: 852 ms  234741/sec
200000 longv add: 1044 ms  191570/sec
200000 longv sub: 1053 ms  189933/sec
200000 longv mul: 1499 ms  133422/sec
200000 longv div: 2436 ms  82101/sec
200000 float add: 1127 ms  177462/sec
200000 float sub: 1136 ms  176056/sec
200000 float mul: 1014 ms  197238/sec
200000 float div: 1862 ms  107411/sec
200000 double add: 1702 ms  117508/sec
200000 double sub: 1766 ms  113250/sec
200000 double mul: 1658 ms  120627/sec
200000 double div: 6065 ms  32976/sec

As you can see ints are faster (but not massively so). So if you have to do a lot of scaling to get things into fixed point the gain may not be that large. The floating point for leJOS is in software (in the firmware), the integer arithmetic is in hardware, but in this case the advantage is rather hidden by the VM overhead. The above times are for operations using local (stack variables). If you use class variables things get slower...

Code: Select all

200000 intc add: 2248 ms  88967/sec
200000 intc sub: 2248 ms  88967/sec
200000 intc mul: 2280 ms  87719/sec
200000 intc div: 2541 ms  78709/sec

Oh and these times are for the latest build of leJOS, which is a fair bit faster (about 30% for some tests), then 0.8. You may want to run your own tests to see what works best for you...


Return to “NXJ Software”

Who is online

Users browsing this forum: No registered users and 2 guests