Channels ▼
RSS

C/C++

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)
{
   result += readLine()
}


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++
}


Figure 9: Multiple hash map.



Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips 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.
 

Video