Benchmarking

Team-Fly

In the J2SE world, there are many tools for examining the performance of code, the location of bottlenecks, and memory usage. Unfortunately, none of this is available in the J2ME world (as of this writing). You'll have to perform bench-marking the old-fashioned way. For this, there are several methods in the MIDP API that will be useful. To test memory use, you can use the following methods in java.lang.Runtime:

 public long freeMemory() public long totalMemory() 

The first method tells how much memory, in bytes, is currently available. The second method gives the total number of bytes in the current runtime environment, whether they are used for objects or not. Interestingly, this number can change, as the host environment (device operating system) can give more memory to the Java runtime environment.

To find out how much memory an object uses, you can do something like this:

 Runtime runtime = Runtime.getRuntime(); long before, after; System.gc(); before = runtime.freeMemory(); Object newObject = new String(); after = runtime.freeMemory(); long size = before - after; 

Aside from examining memory usage, you may also be concerned with the speed of your application. Again, you can test this the old-fashioned way-look at the clock before you start doing something, then look at it again when you're finished. The relevant method comes from the java.lang.System class:

 public static long currentTimeMillis() 

You might calculate the execution time for a method like this:

 long start, finish; start = System.currentTimeMillis(); someMethod(); finish = System.currentTimeMillis(); long duration = finish - start; 


Team-Fly


Wireless Java. Developing with J2ME
ColdFusion MX Professional Projects
ISBN: 1590590775
EAN: 2147483647
Year: 2000
Pages: 129

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net