This repository was archived by the owner on May 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhell.cpp
58 lines (50 loc) · 2.6 KB
/
hell.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Without caching this turns out really slow (obviously)
// Only did one run without optimization flags: 40517 microseconds (3600X CPU)
#include <chrono>
#include <iostream>
void sum_up_to_n(int n) {
// Initialize sum variable
long long int sum = 0;
// Loop through integers from 1 to n
for (int i = 1; i <= n; ++i) {
// Add current integer to sum
sum += i;
}
std::cout << "Sum of integers up to " << n << ": " << sum << '\n';
}
int main() {
auto start = std::chrono::high_resolution_clock::now();
int nums[] = {
100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000,
100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000,
100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000,
100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000,
100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000,
100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000,
100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000,
100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000,
100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000,
100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000,
100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000,
100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000,
100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000,
100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000,
100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000,
100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000,
100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000,
100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000,
100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000,
100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000,
100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000,
100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000,
100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000};
for (int num : nums)
sum_up_to_n(num);
auto end = std::chrono::high_resolution_clock::now();
auto duration =
std::chrono::duration_cast<std::chrono::microseconds>(end - start)
.count();
std::cout << "Program finished in " << duration << " microseconds."
<< std::endl;
return 0;
}