Page 1 of 1

Ruby cpu usage

Posted: Sun Dec 02, 2012 6:57 pm
by unkargherth
Hi fellows

As an SM user, I feel comfortable being able to calculate ( approximately) how much cpu a code module is using

There's anyway to do the same with ruby modules?

It seems not trivial, taking into account that ruby modules use the same "ruby instance" in the whole schematic, but event taking the module out to a new schematic to make the measurement possible, will be a great help

Any idea?

Re: Ruby cpu usage

Posted: Tue Dec 04, 2012 12:44 pm
by support
Tricky one. We don't have a way of doing this at the moment. It would be interesting to look into though.

Re: Ruby cpu usage

Posted: Tue Dec 04, 2012 7:58 pm
by trogluddite
Hmm, yes it would be interesting to know - though in reality we cannot easily do this for 'green' sections either.
Unlike code (always running), any event driven process is going to be hard to get precisely reliable results from - and this is further complicated by Ruby calling GDI (for graphics), or maybe external dll's, in which case it is hard with any CPU monitor to pick apart which part of the process is using what proportion of CPU. Readings are also very variable between different machines, so they will only provide very vague hints about their efficiency when you move them.

But there is a different kind of measurement that may be equally, or even more, useful - most often you would choose code/green/Ruby based on what will best allow you to perform a particular task.
So the question becomes, which is the most efficient way to use Ruby - what combinations of methods, loops, etc. will get you the best performance. And this is far easier to determine.
For example, consider a bit of code like this...

Code: Select all

start = time
10000.times do
   #TEST CODE
end
result = start - time

This will tell you how long a piece of code took to execute - and doing many times over allows a good average of results. Change the TEST CODE to some other routine that does the same thing, and you can compare them for efficiency.
We could also maybe add the "benchmark" libraryto FS from a standard Ruby installation (DWB has been working on a nice clean method for doing this). The "benchmark" library contains methods for doing similar measurements, but in a more accurate way, with a measure of actual CPU time used by only the Ruby thread - so disregarding other stuff that the CPU is doing at the same time (that's my reading of the doc's anyhow - I could be mistaken).