C++: Benchmark Counter

Run the following program and find how fast is your PC in brutal calculations:

//counter.cpp:
//------------
//#include "stdafx.h"

#include <stdio.h>
#include <iostream>
#include <time.h>
#include <conio.h>

int main (int argc, char* argv[])
{
    double x;
    int a;
    time_t start, stop;
   
    printf("a pentium 4, 3.0GHz runs this test in 22 seconds \n");
    printf("please wait... \n\n");
   
    time(&start);
   
    for (double i=0; i<8000000000;i++){
        x=9876543210/123456789;
    }
   
    time(&stop);
   
    printf("elapsed %u seconds (press space to end)\n\n", (int) difftime(stop,start));
   
    do{
        a=getch();//instead of _getch()
    }
    while(!strchr(" ", a));
    return 0;
}

Here is how to compile it:

g++ -c benchmark_counter.cpp
g++ -o benchmark_counter benchmark_counter.o -lcurses

Leave a Reply