 Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.

# Microbenchmarking C++, C#, and Java

Figure 3 shows the results of the `Long` arithmetic test, which replaces the 64-bit double variables with 64-bit `long` variables. Here is the pseudocode:

```while (i < Max)
{
Result -= i++
Result *= i++
Result += i++
Result /= i++
}

``` #### Figure 3: Results.

The trigonometric functions test runs the `sin`, `cos`, `tan`, `log10`, and `sqrt` functions in a loop, performed with 64-bit double arithmetic. Figure 4 presents the results. Here is the pseudocode:

```while (i < Max)
{
sine += sin(i)
cosine += cos(i)
tangent += tan(i)
logarithm +=log10(i)
squareRoot += sqrt(i)
i++
}

``` #### Figure 4: Trigonometric functions.

File I/O performs a write/read of 8,100,000 bytes in/from a text file. Starting with this test, each subsequent test is done 10 times. Figure 5 shows the results. Here is the pseudocode:

```while (i < Max)
{
writeLine ("abcdefghijklmno...")
i++
}
while (not eof)
{
}

``` #### Figure 5: File I/O.

The array test measures the basic array `set` and `get` functions, including allocation of the required memory. Figure 6 shows the results. Here is the pseudocode:

```while (i < Max)
{
x[i] = i + 1
y[i] = 0
i++
}
while (k < 1000)
{
while (j < Max)
{
y[j] += x[j]
j++
}
k++
}

``` #### Figure 6: Array.

Exception handling creates 2x50000 exceptions, which are interleaved. Figure 7 shows the results. Here is the pseudocode:

```while (i < Max)
{
try
{
try
{
if ( i is odd )
{
throw new lo_Exception
}
else
{
throw new hi_Exception
}
}
catch(lo_exception)
{
Lo++
}
}
catch(hi_exception)
{
Hi++
}
i++
}

``` #### Figure 7: Exception.

A single hash map is filled with 32-bit integers via a string key in this test. Then a `find` is performed with a 62.5 percent success ratio of all values; see Figure 8. Here is the pseudocode:

```while (i < Max)
{
insert value of i with key
of i as hex string into hash map
i++
}
i=0
while (i < Max)
{
if( hash map contains key
of i as decimal string )
{
result++
}
i++
}

``` #### Figure 8: Single hash map.

This time, two hash maps are used. One is filled and iterated to perform `find`, `get`, and `set` operations on the second. Figure 9 shows the results. Here is the pseudocode:

```while (i < 10000)
{
insert value of i with key of i
as decimal string into hash map1
i++
}
i=0
while (i < Max)
{
for each entry in hash map1
{
if( hash map2 contains key of hash map1        entry)
{
hash map2 entry value +=
hash map1 entry value
}
else
{
insert hash map1 entry value
into hash map2 via hash map1
entry key
}
}
i++
}

``` ### More Insights To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.

## Featured Reports ## Featured Whitepapers 