rendered paste body// -*- mode: c++ -*-// $Id: sieve.g++,v 1.6 2001/07/11 17:45:46 doug Exp $// http://www.bagley.org/~doug/shootout/// From Bill Lear// with help from Stephane Lajoie//** This copy courtesy of http://www.kano.net/javabench///** Modified to make comparable to the Java version of the benchmark//** Added Timer() code#include <ctime>#include <cstdlib>#include <iostream>using namespace std;int main(int argc, char *argv[]) { size_t NUM = (argc == 2 ? (atoi(argv[1]) < 1 ? 1 : atoi(argv[1])): 1); clock_t start=clock(); int count = 0; bool primes[8192 + 1]; while (NUM--) { count = 0; for(int i = 2; i <= 8192; i++) primes[i] = true; for (int i = 2; i <= 8192; i++) { if (primes[i]) { for (int k = i + i; k <= 8192; k += i) { primes[k] = false; } count++; } } } cout << "Count: " << count << endl; clock_t endt=clock(); std::cout <<"Time: " << double(endt-start)/CLOCKS_PER_SEC * 1000 << " ms\n";}