Why only one uBasic statement per tick? - page 2 - General Discussion and Assistance - CHDK Forum supplierdeeply

Why only one uBasic statement per tick?

  • 15 Replies
  • 8344 Views
*

Offline reyalp

  • ******
  • 14117
Re: Why only one uBasic statement per tick?
« Reply #10 on: 15 / January / 2009, 17:52:08 »
Advertisements
Currently the speed setting statement is now called "set_basic_speedup", but I don't think that's quite right either!
set_statements_per_cycle ?

@fudgey:
Comments in lua are loaded, but are obviously not compiled into the bytecode. We could discard the original lua text, but we don't currently (really, we should probably compile when we load). This only applies to the main text, require()'d files should already do this, but on the downside they aren't loaded till the script is triggered. Note that with hostlua, we should be able to pre-compile the code on the PC.

Discarding rems in ubasic would require changing the loading code (in script.c). You'd have to do some fiddling if you wanted to avoid memory fragmentation. I suppose reading line by line would solve this, and as long as you use buffered io, shouldn't affect performance too much.
Don't forget what the H stands for.

Re: Why only one uBasic statement per tick?
« Reply #11 on: 11 / June / 2009, 15:11:57 »
For what it's worth, I just tested a trivial loop in uBasic and Lua to compare performance (on a Canon G9).

It basically loops from 1 to 1000, incrementing a counter and printing every 100 increments.

uBasic:

Code: [Select]
x=0
s=get_tick_count
for i=1 to 1000
   x = x + 1
   if x%100=0 then print x
next i
print "Result:", x
t=get_tick_count
t=t-s
print "Total time:", t
sleep 5000
print "Done"

Result: 30210ms

Lua:

Code: [Select]
x = 0
start = get_tick_count()
for i=1, 1000 do
   x = x + 1
   if x % 100 == 0 then
      print(x)
   end
end
print("Result: " .. x)
print("Total time: " .. (get_tick_count() - start))
sleep(5000)
print("Done")

Result: 440ms.

So Lua is, for this trivial example, 68 times faster than uBasic. I figured it would be faster, but that's nearly two orders of magnitude.  :)

*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: Why only one uBasic statement per tick?
« Reply #12 on: 14 / June / 2009, 04:56:58 »
If it's just general computation you wish to compare, you may want to run a test that has no print commands anywhere before you stop the clock. I'm not 100% sure, but I think they are kind of slow and it's not purely the script language you're benchmarking if CHDK script console code drawing is taking most of the time.

Re: Why only one uBasic statement per tick?
« Reply #13 on: 16 / June / 2009, 09:42:05 »
If it's just general computation you wish to compare, you may want to run a test that has no print commands anywhere before you stop the clock. I'm not 100% sure, but I think they are kind of slow and it's not purely the script language you're benchmarking if CHDK script console code drawing is taking most of the time.


For a more real-world test I  should have used *more* print statements, not less, I guess. I suppose my point is that "you really should learn Lua". Apart from being more flexible, if it runs faster then that allows more computation in the script, faster reaction times, etc.


*

Offline zeno

  • *****
  • 891
Re: Why only one uBasic statement per tick?
« Reply #14 on: 16 / June / 2009, 11:07:01 »
Things are a little bit more complicated. Both uBasic and Lua have to yield after executing certain statements (eg pressing buttons, shoot, mtion detection etc), so for some scripts you would not notice much difference between the two - both would execute just one statement per tick. Calculations are a different matter of course.
A570, S100, Ixus 127
Author of ASSIST, STICK, WASP, ACID, SDMInst, LICKS, WICKS, MacBoot, UBDB, CFGEdit

Re: Why only one uBasic statement per tick?
« Reply #15 on: 16 / June / 2009, 20:46:58 »
Things are a little bit more complicated. Both uBasic and Lua have to yield after executing certain statements (eg pressing buttons, shoot, mtion detection etc), so for some scripts you would not notice much difference between the two - both would execute just one statement per tick. Calculations are a different matter of course.

Fair point. I'm probably just biased, I'm a sysadmin by trade so I use C-like scripting languages (Perl, Ruby, PHP etc.) all day and uBasic is fairly horrible by comparison. FWIW we did a quick-and-dirty benchmark of various languages at work today (on Linux); Lua is 3 times faster than Perl, 4 times faster than Python and 6 times faster than Ruby. Speed is hardly the only criteria for a language, of course, but I was quite impressed. The more I use Lua, the more I like it. Every now and then I get a "wow, I'm running a Lua program on my camera!" moment. :)

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal