31 lines
827 B
C++
31 lines
827 B
C++
#include "special_sum.h"
|
|
#include "../utils/timing.h"
|
|
#include <iostream>
|
|
#include <chrono>
|
|
#include <stack>
|
|
using namespace std;
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
// check results and compare speeds
|
|
for(size_t n : {15, 1001, 1432987})
|
|
{
|
|
cout << "n = " << n << endl;
|
|
size_t sum_1, sum_2;
|
|
|
|
tic();
|
|
for(size_t i = 0; i < 1000; ++i)
|
|
sum_1 = special_sum_loop(n);
|
|
double time_1 = toc();
|
|
|
|
tic();
|
|
for(size_t i = 0; i < 1000; ++i)
|
|
sum_2 = special_sum_noloop(n);
|
|
double time_2 = toc();
|
|
|
|
cout << "loop: " << sum_1 << "\t\tDuration: " << time_1 << endl;
|
|
cout << "no loop: " << sum_2 << "\t\tDuration: " << time_2 << endl << "---------------------------------------------------" << endl;
|
|
}
|
|
|
|
return 0;
|
|
}
|