As the title says. How do you write (and run) a correct micro-benchmark in Java?
I'm looking here for code samples and comments illustrating various things to think about.
Example: Should the benchmark measure time/iteration or iterations/time, and why?
Near Duplicate of: http://stackoverflow.com/questions/410437/is-stopwatch-benchmar...
I'm writing some micro-benchmarking code for some very short operations in C. For example, one thing I'm measuring is how many cycles are needed to call an empty function depending on the number of arguments passed.
Currently, I'm timing using an RDTSC instruction before and after each operation to get the CPU's cycle count. However, I...
Here is a sample code:
public class TestIO{
public static void main(String[] str){
TestIO t = new TestIO();
t.fOne();
t.fTwo();
t.fOne();
t.fTwo();
}
public void fOne(){
long t1, t2;
t1 = System.nanoTime();
int i = 10;
int j = 10;
int k = j*i;
System.out.println(k);
...
When comparing the performance of operations this is how I would typicaly do the tests:
<?php
$w = 'world';
$start1 = microtime(true);
for($i=0;$i<10000;$i++)
echo 'Hello ' . $w . '!';
$end1 = microtime(true);
$start2 = microtime(true);
for($i=0;$i<10000;$i++)
echo "Hello $w!";
$end2 = microtime(true);
$start3 = microtime(true...
I am looking for ways to perform micro-benchmarks on multi-core processors.
Context:
At about the same time desktop processors introduced out-of-order execution that made performance hard to predict, they, perhaps not coincidentally, also introduced special instructions to get very precise timings. Example of these instructions are rdt...