Zip and Skip Tries
Loading...
Searching...
No Matches
data.hpp
Go to the documentation of this file.
1
10#pragma once
11
12#include <chrono> // For WallTimer
13#include <ctime> // For CPUTimer
14#include <string>
15#include <fstream> // Included for get_hostname implementation detail, though not strictly needed for declarations
16#include <iostream> // Included for WallTimer/CPUTimer print methods
17
19static const std::string GENETIC_DATA_DIRECTORY = "data-genetic/";
21static const std::string SYNTHETIC_DATA_DIRECTORY = "data-synthetic/";
23static const std::string SEARCH_DATA_FILENAME = "search-data-";
25static const std::string CONSTRUCTION_DATA_FILENAME = "construction-data-";
27static const std::string REMOVAL_DATA_FILENAME = "removal-data-";
29static const std::string CSV_EXTENSION = ".csv";
30
36inline const std::string& get_data_directory(bool is_genetic = false)
37{
39}
40
56void save_search_data(const std::string& method, size_t n, size_t m, size_t l, size_t num_nanoseconds, size_t num_repetitions = 1, size_t min_par_compare = 0, bool is_genetic = false);
57
73void save_construction_data(const std::string& method, size_t n, size_t m, size_t l, size_t num_nanoseconds, size_t num_repetitions = 1, size_t min_par_compare = 0, bool is_genetic = false);
74
90void save_removal_data(const std::string& method, size_t n, size_t m, size_t l, size_t num_nanoseconds, size_t num_repetitions = 1, size_t min_par_compare = 0, bool is_genetic = false);
91
97std::string get_hostname();
99static const std::string HOSTNAME = get_hostname();
100
107std::string pretty_print(size_t nanoseconds);
108
116{
117 std::chrono::high_resolution_clock::time_point start_time;
120 WallTimer() = default; // Use default constructor
121
127 {
128 auto end = std::chrono::high_resolution_clock::now();
129 auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(end - start_time);
130 return duration.count();
131 }
132
138 void start(const std::string& prompt = "", bool reset = true) noexcept
139 {
140 if (reset)
141 {
142 start_time = std::chrono::high_resolution_clock::now();
143 }
144
145 if (!prompt.empty())
146 {
147 // Use printf for potentially better performance in tight loops compared to std::cout
148 printf("%s... \t", prompt.c_str());
149 fflush(stdout); // Ensure the prompt is displayed immediately
150 }
151 }
152
159 {
161 printf("done (%s)\n", pretty_print(nanoseconds).c_str());
162 fflush(stdout); // Ensure the output is displayed immediately
163 return nanoseconds;
164 }
165};
166
175{
176 std::clock_t start_time;
179 CPUTimer() = default; // Use default constructor
180
186 {
187 auto end = std::clock();
188 // Calculate duration in nanoseconds based on clock ticks and CLOCKS_PER_SEC
189 return static_cast<size_t>(static_cast<double>(end - start_time) * 1e9 / CLOCKS_PER_SEC);
190 }
191
197 void start(const std::string& prompt = "", bool reset = true) noexcept
198 {
199 if (reset)
200 {
201 start_time = std::clock();
202 }
203
204 if (!prompt.empty())
205 {
206 printf("%s... \t", prompt.c_str());
207 fflush(stdout); // Ensure the prompt is displayed immediately
208 }
209 }
210
217 {
219 printf("done (%s)\n", pretty_print(nanoseconds).c_str());
220 fflush(stdout); // Ensure the output is displayed immediately
221 return nanoseconds;
222 }
223};
T * alloc_to_device(size_t size)
Allocates memory on the CUDA device.
static const std::string GENETIC_DATA_DIRECTORY
Directory path for storing data related to genetic datasets.
Definition data.hpp:19
static const std::string REMOVAL_DATA_FILENAME
Base filename prefix for removal performance data files.
Definition data.hpp:27
static const std::string SYNTHETIC_DATA_DIRECTORY
Directory path for storing data related to synthetic datasets.
Definition data.hpp:21
static const std::string CSV_EXTENSION
Standard file extension for Comma Separated Value files.
Definition data.hpp:29
static const std::string SEARCH_DATA_FILENAME
Base filename prefix for search performance data files.
Definition data.hpp:23
std::string get_hostname()
Retrieves the hostname of the machine executing the code.
Definition data.cpp:50
void save_removal_data(const std::string &method, size_t n, size_t m, size_t l, size_t num_nanoseconds, size_t num_repetitions=1, size_t min_par_compare=0, bool is_genetic=false)
Saves removal performance data to a CSV file.
Definition data.cpp:37
void save_search_data(const std::string &method, size_t n, size_t m, size_t l, size_t num_nanoseconds, size_t num_repetitions=1, size_t min_par_compare=0, bool is_genetic=false)
Saves search performance data to a CSV file.
Definition data.cpp:11
static const std::string CONSTRUCTION_DATA_FILENAME
Base filename prefix for construction performance data files.
Definition data.hpp:25
void save_construction_data(const std::string &method, size_t n, size_t m, size_t l, size_t num_nanoseconds, size_t num_repetitions=1, size_t min_par_compare=0, bool is_genetic=false)
Saves construction performance data to a CSV file.
Definition data.cpp:24
std::string pretty_print(size_t nanoseconds)
Converts a duration in nanoseconds to a human-readable string format.
Definition data.cpp:65
static const std::string HOSTNAME
Constant string storing the hostname, retrieved once at program startup.
Definition data.hpp:99
const std::string & get_data_directory(bool is_genetic=false)
Gets the appropriate data directory path based on the data type.
Definition data.hpp:36
A timer class measuring CPU time used by the current process using std::clock().
Definition data.hpp:175
size_t print() noexcept
Prints the elapsed CPU time since the last start/reset to stdout.
Definition data.hpp:216
std::clock_t start_time
Definition data.hpp:176
void start(const std::string &prompt="", bool reset=true) noexcept
Starts or resets the CPU timer and optionally prints a starting message.
Definition data.hpp:197
CPUTimer()=default
Default constructor.
size_t elapsed_nanoseconds() const noexcept
Calculates the elapsed CPU time since the timer was started.
Definition data.hpp:185
A timer class measuring wall-clock time using std::chrono::high_resolution_clock.
Definition data.hpp:116
size_t print() noexcept
Prints the elapsed time since the last start/reset to stdout.
Definition data.hpp:158
void start(const std::string &prompt="", bool reset=true) noexcept
Starts or resets the timer and optionally prints a starting message.
Definition data.hpp:138
WallTimer()=default
Default constructor.
std::chrono::high_resolution_clock::time_point start_time
Definition data.hpp:117
size_t elapsed_nanoseconds() const noexcept
Calculates the elapsed time since the timer was started.
Definition data.hpp:126