Benchmark in processing.org

Trying to better understand the functioning of the Java language (in particular of processing) I decided to build a small class of benchmark with which to keep monitored the duration of some operations computationally expensive. The usage of the class is very simple: copy the file. pde in the folder of your sketch and open the main file (for example mySketch.pde in a folder with the same name “mySketch”). The usage that I suggested (but you are free to adapt it to your taste and your needs) is to declare an instance of the class benchmark at the beginning of the code, then the instance will be initialized at the beginning of phase to be monitored specifying the subject of control (a simple string that will be reported in the console) and successively is close. Will then appear on the console the duration of the operation (or loop of operations), in milliseconds. You don’t need to create a new instance of the benchmark class for each control, just overwrite the same every time.

usage example:

benchmark myBenchmark;

... code ...

myBenchmark = new benchmark("myOperation time");
...operations...
myBenchmark.end(); //return in console "myOperation time: ###ms"

...code...

myBenchmark = new benchmark("myAnotherOperation time");
...another operation...
myBenchmark.end(); //return in console "myAnotherOperation time: ###ms"

This is really simple, but I hope useful.

download benchmark.pde


[edit]
I improved my benchmark using class method static instead of default instance. In this way it is not possible to output nested benchmark controls (you can have a nested control copying the class with a different name for every hierarchy level) on the other hand it is possible to access to benchmark methods without having to instantiate the generic class benchmark.
I also insert a memory control that display total memory used by virtual machine and a delta memory that, after the calling of garbage collector, evaluate the memory used by myOperation.

usage example:

...
benchmark.begin("myOperation");
... operations ...
benchmark.end();
...

benchmark_example

example of benchmark output

download benchmark_static.pde

Lascia un commento

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...

%d blogger cliccano Mi Piace per questo: