-
Notifications
You must be signed in to change notification settings - Fork 19
/
main.cpp
72 lines (59 loc) · 1.46 KB
/
main.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include "rust_part.h"
#include <chrono>
const std::string &get_name(const Person &person)
{
return person.name;
}
std::unique_ptr<Person> make_person()
{
return std::make_unique<Person>();
}
bool shared::Color::is_black() const noexcept
{
return this->r == 0 && this->g == 0 && this->b == 0;
}
int cpp_echo(int val)
{
return val;
}
int test_fun()
{
int sum = 0;
for (int i = 0; i < 1000000; i += 1)
{
sum += rust_part::rust_echo(i);
}
return sum;
}
int test_inline()
{
int sum = 0;
for (int i = 0; i < 1000000; i += 1)
{
sum += cpp_echo(i);
}
return sum;
}
void test_lto()
{
auto t1 = std::chrono::high_resolution_clock::now();
auto sum = test_fun();
auto t2 = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(t2 - t1).count();
std::cout << "Calling rust function"
<< ", time elapsed: " << duration << " ns." << std::endl;
t1 = std::chrono::high_resolution_clock::now();
sum = test_inline();
t2 = std::chrono::high_resolution_clock::now();
duration = std::chrono::duration_cast<std::chrono::nanoseconds>(t2 - t1).count();
std::cout << "Calling c++ function"
<< ", time elapsed: " << duration << " ns." << std::endl;
}
int main()
{
auto thing = rust_part::make_shared_thing();
rust_part::print_shared_thing(thing);
test_lto();
return 0;
}