-
Notifications
You must be signed in to change notification settings - Fork 9
/
test_factoriel.hpp
67 lines (48 loc) · 1.47 KB
/
test_factoriel.hpp
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
59
60
61
62
63
64
65
66
67
#pragma once
namespace Factoriel {
#include <iostream>
inline int factoriel0(int n) {
if(n==0) return 1;
else return factoriel0(n-1)*n;
}
inline int factoriel1(int n) {
int r = 1;
DISABLE_SIMD_UNROLL
for(int k=n; k>0; --k)
r *= k;
return r;
}
inline int factoriel2(int n) {
int r = 1;
DISABLE_SIMD_UNROLL
for(int k=1; k<=n; ++k)
r *= k;
return r;
}
constexpr int getTestSize() {
return 100000000;
}
void test() {
printf("Testing factoriel ...\n");
auto s1 = getTime();
DISABLE_SIMD_UNROLL
for(int k=0; k<100; k++) {
volatile int r1 = factoriel1(getTestSize());
}
auto e1 = getTime();
auto s2 = getTime();
DISABLE_SIMD_UNROLL
for(int k=0; k<100; k++) {
volatile int r2 = factoriel2(getTestSize());
}
auto e2 = getTime();
auto s3 = getTime();
DISABLE_SIMD_UNROLL
for(int k=0; k<100; k++) {
volatile int r3 = factoriel0(getTestSize());
}
auto e3 = getTime();
std::cout << "\tfactoriel 1: " << diffclock(e1, s1) << std::endl << "\tfactoriel 2: " << diffclock(e2, s2) << std::endl << "\trecursive: "<< diffclock(e3, s3);
std::cout << "\n **** \n\n";
}
}