Click here to Skip to main content
Click here to Skip to main content

KISS code block execution-speed benchmark

, 31 May 2006
Rate this:
Please Sign up or sign in to vote.
A utility for "Keep It Simple Stupid" code block execution-speed benchmarking.


"Yesterday I was working on some code, that I think is time critical. So I wrote myself a file, a really little test project, to visualize the elapsed CPU cycles (of my life) that passed while executing the mentioned code block. As the work progressed I also wanted to see the differences, measured in cycles, between single versions, or in other words how good or bad I was in optimizing it. I wasn't quite finished with my work when I suddenly saw, that the little speed testing utility could be something, that I might share." I wrote this text some time ago. Since then my benchmark evolved...


Flow Chart


  1. Create new empty console project.
  2. Add benchmark.h and benchmark.cpp into the project.
  3. Add an empty .cpp file into the project. Your .cpp file should have following layout:
    #include <benchmark.h>
    // put all your include files here together with globals
    // expands to int main(int, char**)
    //      - don't define your own  !!!
        // repeat following code for each test you wish to run
        // below are helper macros for safe access to test parameters 
        // each parameter once set is valid for all consecutive tests 
        // until changed by a call to it`s appropriate setter 
        // parameters are set in this order:
        // 1. default values - "Generic Test" in dirty environment
        //           with 5 chaching and 10,000 testing iterations
        // 2. command line arguments - override default values
        //           (see below for possible switches)
        // 3. macro setters
        //sets test description - may be omitted
        SET_DESCRIPTION(formatting string)
        //sets number of chaching iterations - may be omitted
        //sets number of testing iterations - may be omitted
        //sets clean environment on or off - may be omitted
        // use following macros to encapsulate chaching
        // of tested code - may be omitted
        // put both tested code blocks here
        // this is the actual test
        // put first tested code block here
        // put second tested code block here
        // end of a single test
  4. Compile the project and run the benchmark:
    <appname> [[-f name | -c state | -a number | -i number] | [-h]]
         f - specify log file 'name', if you omit this parameter
             the default name 'benchmark.log' will be used
         c - runs the tests in 'state' 0 (dirty) or 1 (clean)
             if you have hard coded the 'states' of your tests,
             this parameter has no effect
         a - sets the global 'number' of caching iterations,
             if you have hard coded this value for your tests,
             this parameter has no effect
         i - sets the global 'number' of testing iterations,
             if you have hard coded this value for your tests,
             this parameter has no effect
         h - shows this help

Last Words

That's all. For further info on this topic take a look at the:

  • Approximate Math Library for Intel® Streaming SIMD Extensions.
  • How to optimize for the Pentium family of microprocessors, By Agner Fog, Ph.D. Copyright © 1996 - 2004.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

oto spal

Slovakia Slovakia
No Biography provided

Comments and Discussions

GeneralNeed some help! Pinmemberdiduke1-Dec-05 18:26 
GeneralRe: Need some help! Pinmemberoto spal4-Dec-05 10:19 
GeneralRe: Need some help! Pinmemberdiduke5-Dec-05 1:17 
GeneralRe: Need some help! Pinmemberoto spal6-Dec-05 12:29 
could you run the test.exe (included in the download) without getting the error? could you please reveal the kind of your cpu? Confused | :confused:
if (xx + xy) % 2 return xx else return xy
GeneralRe: Need some help! Pinmemberdiduke7-Dec-05 5:33 
GeneralRe: Need some help! Pinmemberoto spal12-Dec-05 3:09 
GeneralRe: Need some help! Pinmemberdiduke12-Dec-05 3:36 
GeneralRe: Need some help! Pinmemberoto spal12-Dec-05 13:07 
QuestionRDTSC isn't a great choice nowadays why not use QPC? PinmemberHal Angseesing16-Nov-05 4:39 
AnswerRe: RDTSC isn't a great choice nowadays why not use QPC? Pinmemberoto spal16-Nov-05 15:18 
GeneralGood article but.. PinmemberRobert Buldoc12-Nov-05 15:08 
GeneralRe: Good article but.. Pinmemberoto spal13-Nov-05 16:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150326.1 | Last Updated 31 May 2006
Article Copyright 2005 by oto spal
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid