forked from microsoft/php-sdk-binary-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
51 lines (44 loc) · 1.11 KB
/
Copy pathmain.cpp
File metadata and controls
51 lines (44 loc) · 1.11 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#if defined(__clang__)
#define NO_INLINE __attribute__((noinline))
#else
#define NO_INLINE __attribute__((noinline))
#endif
static NO_INLINE void test(int n, void (*p)(int, int, int)) {
for (int i = 0; i <= n; i++)
{
for (int j = 0; j <= n; j++)
{
for (int k = 0; k <= n; k++)
{
if (p && i + j + k == n && i * i + j * j == k * k)
{
p(i, j, k);
}
}
}
}
}
static NO_INLINE void test_print(int a, int b, int c) {
printf("The result %d^2 + %d^2 = %d^2 !\n", a, b, c);
}
int main()
{
clock_t start, finish;
start = clock();
double duration;
test(1000, test_print);
finish = clock();
duration = (double)(finish - start) / CLOCKS_PER_SEC;
printf("First Used %f seconds\n", duration);
for (int i = 0; i <= 10; i++)
{
test(1000, NULL);
}
finish = clock();
duration = (double)(finish - start) / CLOCKS_PER_SEC;
printf("All Used %f seconds\n", duration);
return 0;
}