-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtest_performance.cpp
177 lines (153 loc) · 6.39 KB
/
test_performance.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/**
* Copyright (C) 2019 Dean De Leo, email: dleo[at]cwi.nl
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "gtest/gtest.h"
#include <cstdio>
#include <cstdlib> // getenv
#include <iostream>
#include <string>
#include "common/system.hpp"
#include "common/timer.hpp"
#include "experiment/insert_only.hpp"
#include "graph/edge_stream.hpp"
#include "library/baseline/adjacency_list.hpp"
#if defined(HAVE_LLAMA)
#include "library/llama/llama_internal.hpp"
#include "library/llama/llama_ref.hpp"
#endif
using namespace common;
using namespace gfe::experiment;
using namespace gfe::library;
using namespace std;
extern char** environ;
constexpr static bool is_directed = false; // whether the graph is directed
static int num_threads_default = 1;
static int get_num_threads(){
static const char* gfe_num_threads = getenv("GFE_NUM_THREADS");
if(gfe_num_threads == nullptr){
cout << "Warning: env. var. GFE_NUM_THREADS not set. Using the default: " << num_threads_default << endl;
return num_threads_default;
} else {
return atoi(gfe_num_threads);
}
}
static const string path_graph_default = common::filesystem::directory_executable() + "/graphs/ldbc_graphalytics/example-undirected.properties";
static string get_path_graph(){
static const char* path_graph = getenv("GFE_PATH_GRAPH");
if(path_graph == nullptr){
cout << "Warning: env. var. GFE_PATH_GRAPH not set. Using the default: " << path_graph_default << endl;
return path_graph_default;
} else {
return string(path_graph);
}
}
static const uint64_t num_iterations_default = 1ull << 10;
[[maybe_unused]] static uint64_t get_num_iterations(){
static const char* gfe_num_iterations = getenv("GFE_NUM_ITERATIONS");
if(gfe_num_iterations == nullptr){
cout << "Warning: env. var. GFE_NUM_ITERATIONS not set. Using the default: " << num_iterations_default << endl;
return num_iterations_default;
} else {
return strtoull(gfe_num_iterations, nullptr, 10);
}
}
TEST(Performance, InsertOnly) {
auto impl = make_shared<AdjacencyList>(is_directed);
Timer timer;
string path_graph = get_path_graph();
cout << "[Performance::InsertOnly] Loading the graph from `" << path_graph << "' ... \n";
timer.start();
auto stream = make_shared<gfe::graph::WeightedEdgeStream>(path_graph);
timer.stop();
cout << "Graph loaded in " << timer << "\n";
stream->permute(1910);
int num_threads = get_num_threads();
cout << "[Performance::InsertOnly] Executing the insertions using " << num_threads << " threads ...\n";
timer.start();
InsertOnly experiment(impl, move(stream), num_threads);
experiment.execute();
timer.stop();
cout << "Execution completed in " << timer << "\n";
}
TEST(Performance, LCC) {
auto impl = make_shared<AdjacencyList>(is_directed);
Timer timer;
string path_graph = get_path_graph();
cout << "[Performance::LCC] Loading the graph from `" << path_graph << "' ... \n";
timer.start();
auto stream = make_shared<gfe::graph::WeightedEdgeStream>(path_graph);
timer.stop();
cout << "Graph loaded in " << timer << "\n";
stream->permute(1910);
int num_threads = get_num_threads();
cout << "[Performance::LCC] Executing the insertions using " << num_threads << " threads ...\n";
timer.start();
InsertOnly experiment(impl, move(stream), num_threads);
experiment.execute();
timer.stop();
cout << "Execution completed in " << timer << "\n";
cout << "[Performance::LCC] Executing the LCC algorithm ...\n";
timer.start();
impl->lcc();
timer.stop();
cout << "Execution completed in " << timer << "\n";
}
#if defined(HAVE_LLAMA)
static void _test_perf_run_llama(){
auto impl = make_shared<LLAMAClass>(is_directed);
Timer timer;
string path_graph = get_path_graph();
cout << "[Performance::LLAMA_Iterator_Overhead] Loading the graph from `" << path_graph << "' ... \n";
timer.start();
auto stream = make_shared<gfe::graph::WeightedEdgeStream>(path_graph);
timer.stop();
cout << "Graph loaded in " << timer << "\n";
stream->permute(1910);
int num_threads = get_num_threads();
cout << "[Performance::LLAMA_Iterator_Overhead] Executing the insertions using " << num_threads << " threads...\n";
timer.start();
InsertOnly experiment(impl, move(stream), num_threads);
experiment.execute();
timer.stop();
cout << "Execution completed in " << timer << "\n";
uint64_t num_iterations = get_num_iterations();
uint64_t num_vertices = impl->num_vertices();
cout << "[Performance::LLAMA_Iterator_Overhead] Initialising " << num_iterations << " the output iterator...\n";
auto instance = dynamic_cast<LLAMAClass*>(impl.get());
shared_lock<LLAMAClass::shared_mutex_t> slock(instance->m_lock_checkpoint);
auto graph = instance->get_snapshot();
timer.start();
for(uint64_t i = 0; i < num_iterations; i++){
ll_edge_iterator iterator;
graph.out_iter_begin(iterator, i % num_vertices);
}
timer.stop();
double time_per_item_usecs = static_cast<double>(timer.microseconds()) / num_iterations;
cout << "Execution completed in " << timer << ". Init time per item: " << time_per_item_usecs << " microseconds\n";
cout << "[Performance::LLAMA_Iterator_Overhead] Initialising " << num_iterations << " the input iterator...\n";
timer.start();
for(uint64_t i = 0; i < num_iterations; i++){
ll_edge_iterator iterator;
graph.out_iter_begin(iterator, i % num_vertices);
}
timer.stop();
time_per_item_usecs = static_cast<double>(timer.microseconds()) / num_iterations;
cout << "Execution completed in " << timer << ". Init time per item: " << time_per_item_usecs << " microseconds\n";
}
TEST(Performance, LLAMA_Iterator_Overhead) {
_test_perf_run_llama();
}
#endif