title: Why AES-128 performance is not %40 better than AES-256
body: <p>I am making performance tests over AES-128 and AES-256. But my results are around %20. I am using Intel Core 2 Duo 800 MHz. 2.60 GHz. 6 MB Cache Memory T9500 CPU and Linux Mint 17.2 Rosa Xfce Os. Is there a problem with my testing? Any help would be appreciated.</p>
  
  <p>My testing code is here:
  Headings;</p>
  
  <pre><code>// g++ -g3 -ggdb -O0 -DDEBUG -I/usr/include/cryptopp AESCBC128.cpp -o AESCBC128.exe -lcryptopp -lpthread
  // g++ -g -O2 -DNDEBUG -I/usr/include/cryptopp AESCBC128.cpp -o AESCBC128.exe -lcryptopp -lpthread
    #include "osrng.h"
     using CryptoPP::AutoSeededRandomPool;
     #include &lt;iostream&gt;
     using std::cout;
     using std::cerr;
     using std::endl;
     #include &lt;string&gt;
     using std::string;
     #include &lt;cstdlib&gt;
     using std::exit;
     #include "cryptlib.h"
     using CryptoPP::Exception;
     #include "hex.h"
     using CryptoPP::HexEncoder;
     using CryptoPP::HexDecoder;
     #include "filters.h"
     using CryptoPP::StringSink;
     using CryptoPP::StringSource;
     using CryptoPP::StreamTransformationFilter;
     #include "aes.h"
     using CryptoPP::AES;
     #include "ccm.h"
     using CryptoPP::CBC_Mode;
     #include "assert.h"
     #include&lt;sstream&gt;
     const double CLOCK_TICKS_PER_SECOND = 1000000.0;
  </code></pre>
  
  <p>And my code (for AES-256);</p>
  
  <pre><code> int main(int argc, char* argv[]){
   AutoSeededRandomPool prng;
  
   byte key[AES::MAX_KEYLENGTH];
   prng.GenerateBlock(key, sizeof(key));
  
   byte iv[AES::BLOCKSIZE];
   prng.GenerateBlock(iv, sizeof(iv));
  
   CBC_Mode&lt; AES &gt;::Encryption e;
   e.SetKeyWithIV(key, sizeof(key), iv);
  </code></pre>
  
  <p>And my code (for AES-128);</p>
  
  <pre><code> int main(int argc, char* argv[]){
   AutoSeededRandomPool prng;
  
   byte key[AES::DEFAULT_KEYLENGTH];
   prng.GenerateBlock(key, sizeof(key));
  
   byte iv[AES::BLOCKSIZE];
   prng.GenerateBlock(iv, sizeof(iv));
  
   CBC_Mode&lt; AES &gt;::Encryption e;
   e.SetKeyWithIV(key, sizeof(key), iv);
  </code></pre>
  
  <p>I use crypto++ test data rijndael.dat as plianText (1020 bytes). It is like;</p>
  
  <pre><code>std::string plain = "000102030405060708090A0B0C0D....
  </code></pre>
  
  <p>My testing code;</p>
  
  <pre><code>clock_t startTime, finishTime;      
  std::string plain, cipher, encoded, recovered;   
  startTime = clock();  
  for ( int i = 0; i &lt; 200000; i++ )
  {
      // clean up for next round
      cipher = "";
  
  try
  {
  
  // The StreamTransformationFilter removes
  //  padding as required.
  StringSource s(plain, true, 
      new StreamTransformationFilter(e,
          new StringSink(cipher)
      ) // StreamTransformationFilter
  ); // StringSource
   }
    catch(const CryptoPP::Exception&amp; e)
     {
        cerr &lt;&lt; e.what() &lt;&lt; endl;
        exit(1);
      }  
   } // end-for  
    // save current time just after finishing the encryption loop
     finishTime = clock();
  </code></pre>
  
  <p>And I am keeping results with;</p>
  
  <pre><code> double executionTimeInSec = double( finishTime - startTime ) / CLOCK_TICKS_PER_SECOND;    
  
   std::cout &lt;&lt; "Encryption loop execution time: " &lt;&lt; executionTimeInSec * 1000.0 &lt;&lt; " microseconds." &lt;&lt; std::endl;
  
   std::cout &lt;&lt; "Plain text size: " &lt;&lt; plain.size() &lt;&lt; " bytes." &lt;&lt; std::endl;
  
   double data_rate_MiBps = ((double)plain.size() / 1048576) / ((double)executionTimeInSec) ;
  
   std::cout &lt;&lt; "Encryption/decryption loop execution time MB/S: " &lt;&lt; data_rate_MiBps &lt;&lt; " MB/S." &lt;&lt; std::endl; 
    return 0;
   }
  </code></pre>
  
  <p>Finally my results are here;</p>
  
  <pre><code>AES-128/CBC ----------
             2037.41 encryption loop execution time (microseconds)
             0.083 microseconds for Key Setup and IV
             95.48 Encrypiton loop execution time (MIB/Seconds)
  AES-256/CBC ----------
             2470.86 encryption loop execution time (microseconds)
             0.092 microseconds for Key Setup and IV
             78.72 Encrypiton loop execution time (MIB/Seconds)
  </code></pre>