-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbenchmark.cpp
More file actions
75 lines (68 loc) · 1.67 KB
/
benchmark.cpp
File metadata and controls
75 lines (68 loc) · 1.67 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* benchmark.cpp
*
* Created on: 6 oct. 2013
* Author: Loic Oudot
*/
#include <iostream>
#include <time.h>
#include "java4cpp/java_classes.h"
#include "benchmark.h"
using namespace java4cpp::demos;
void allBenchmark()
{
std::cout << "================================" << std::endl;
std::cout << "Benchmark" << std::endl;
std::cout << "================================" << std::endl;
noArgBenchmark();
primitiveArgBenchmark();
classArgBenchmark();
}
void noArgBenchmark()
{
Benchmark benchmark;
clock_t start = clock();
long nbCall = 0;
do
{
for (int i = 0; i < 10000; ++i)
{
benchmark.noArgMethod();
}
++nbCall;
} while ((clock() - start) / CLOCKS_PER_SEC < 1);
std::cout << "java4cpp no arg method call speed: " << nbCall * 10000 << " method calls/sec" << std::endl;
}
void primitiveArgBenchmark()
{
Benchmark benchmark;
clock_t start = clock();
long nbCall = 0;
int a = 2;
double b = 3.0;
do
{
for (int i = 0; i < 10000; ++i)
{
benchmark.primitiveArgMethod(a, b);
}
++nbCall;
} while ((clock() - start) / CLOCKS_PER_SEC < 1);
std::cout << "java4cpp primitive arg method call speed: " << nbCall * 10000 << " method calls/sec" << std::endl;
}
void classArgBenchmark()
{
Benchmark benchmark;
clock_t start = clock();
long nbCall = 0;
Benchmark a;
do
{
for (int i = 0; i < 10000; ++i)
{
Benchmark result = benchmark.classArgMethod(a);
}
++nbCall;
} while ((clock() - start) / CLOCKS_PER_SEC < 1);
std::cout << "java4cpp class arg method call speed: " << nbCall * 10000 << " method calls/sec" << std::endl;
}