Upload files to "ex1C_summation_of_specified_numbers"
This commit is contained in:
parent
c271205a39
commit
c70572f1b9
3 changed files with 64 additions and 0 deletions
31
ex1C_summation_of_specified_numbers/main.cpp
Normal file
31
ex1C_summation_of_specified_numbers/main.cpp
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue