Zip and Skip Tries
Loading...
Searching...
No Matches
Classes | Functions | Variables
data.hpp File Reference

Defines utilities for managing performance data logging and timing. More...

#include <chrono>
#include <ctime>
#include <string>
#include <fstream>
#include <iostream>
Include dependency graph for data.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  WallTimer
 A timer class measuring wall-clock time using std::chrono::high_resolution_clock. More...
 
struct  CPUTimer
 A timer class measuring CPU time used by the current process using std::clock(). More...
 

Functions

const std::stringget_data_directory (bool is_genetic=false)
 Gets the appropriate data directory path based on the data type.
 
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.
 
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.
 
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.
 
std::string get_hostname ()
 Retrieves the hostname of the machine executing the code.
 
std::string pretty_print (size_t nanoseconds)
 Converts a duration in nanoseconds to a human-readable string format.
 

Variables

static const std::string GENETIC_DATA_DIRECTORY = "data-genetic/"
 Directory path for storing data related to genetic datasets.
 
static const std::string SYNTHETIC_DATA_DIRECTORY = "data-synthetic/"
 Directory path for storing data related to synthetic datasets.
 
static const std::string SEARCH_DATA_FILENAME = "search-data-"
 Base filename prefix for search performance data files.
 
static const std::string CONSTRUCTION_DATA_FILENAME = "construction-data-"
 Base filename prefix for construction performance data files.
 
static const std::string REMOVAL_DATA_FILENAME = "removal-data-"
 Base filename prefix for removal performance data files.
 
static const std::string CSV_EXTENSION = ".csv"
 Standard file extension for Comma Separated Value files.
 
static const std::string HOSTNAME = get_hostname()
 Constant string storing the hostname, retrieved once at program startup.
 

Detailed Description

Defines utilities for managing performance data logging and timing.

This file provides constants for data directories and filenames, functions for saving performance metrics (search, construction, removal times) to CSV files, and timer classes (WallTimer, CPUTimer) for measuring execution time. It helps in systematically collecting and organizing benchmark results.

Definition in file data.hpp.

Function Documentation

◆ get_data_directory()

const std::string & get_data_directory ( bool  is_genetic = false)
inline

Gets the appropriate data directory path based on the data type.

Parameters
is_geneticIf true, returns the genetic data directory; otherwise, returns the synthetic data directory.
Returns
const std::string& A constant reference to the selected directory path string.

Definition at line 36 of file data.hpp.

37{
39}
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 SYNTHETIC_DATA_DIRECTORY
Directory path for storing data related to synthetic datasets.
Definition data.hpp:21

◆ get_hostname()

std::string get_hostname ( )

Retrieves the hostname of the machine executing the code.

Implemented by reading from /proc/sys/kernel/hostname on Linux systems.

Returns
std::string The hostname.

Definition at line 50 of file data.cpp.

51{
52 std::string hostname;
53 // Attempt to open the hostname file provided by the kernel (Linux-specific).
54 std::ifstream file("/proc/sys/kernel/hostname");
55 if (file.is_open()) // Check if the file was successfully opened
56 {
57 // Read the entire line (hostname) from the file.
58 std::getline(file, hostname);
59 // File is automatically closed when 'file' goes out of scope.
60 }
61 // Return the retrieved hostname (or an empty string if reading failed).
62 return hostname;
63}

◆ pretty_print()

std::string pretty_print ( size_t  nanoseconds)

Converts a duration in nanoseconds to a human-readable string format.

Formats the time into hours (h), minutes (m), seconds (s), and milliseconds (ms) as appropriate.

Parameters
nanosecondsThe duration in nanoseconds.
Returns
std::string A formatted string representing the duration (e.g., "1m 30s 500ms", "120ms").

Definition at line 65 of file data.cpp.

66{
67 size_t milliseconds = nanoseconds / 1e6;
68 size_t seconds = nanoseconds / 1e9;
69 size_t minutes = seconds / 60;
70 size_t hours = minutes / 60;
71
72 // Build the output string based on the largest significant unit.
73 if (hours > 0)
74 {
75 // Format as h, m, s, ms
76 return std::to_string(hours) + "h " + std::to_string(minutes % 60) + "m " + std::to_string(seconds % 60) + "s " + std::to_string(milliseconds % 1000) + "ms";
77 }
78 else if (minutes > 0)
79 {
80 // Format as m, s, ms
81 return std::to_string(minutes) + "m " + std::to_string(seconds % 60) + "s " + std::to_string(milliseconds % 1000) + "ms";
82 }
83 else if (seconds > 0)
84 {
85 // Format as s, ms
86 return std::to_string(seconds) + "s " + std::to_string(milliseconds % 1000) + "ms";
87 }
88 else // Only milliseconds or less
89 {
90 // Format as ms
91 return std::to_string(milliseconds) + "ms";
92 }
93}

◆ save_construction_data()

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.

Appends a record to a CSV file named based on the hostname, method, and data type. The file stores parameters and timing results for data structure construction operations.

Parameters
methodA string identifying the construction method or data structure used (e.g., "SkipTrie", "ParallelZipTrie").
nThe number of elements inserted during the construction.
mThe characteristic length of the elements being inserted (e.g., average or fixed string length).
lA parameter potentially representing the average LCP length of the inserted data, or another characteristic.
num_nanosecondsThe total time taken for the construction operation(s), in nanoseconds.
num_repetitionsThe number of times the construction operation was repeated or batched. Defaults to 1.
min_par_compareA parameter potentially related to parallel comparison thresholds used during construction. Defaults to 0.
is_geneticFlag indicating whether the data pertains to genetic (true) or synthetic (false) datasets. Defaults to false.

Definition at line 24 of file data.cpp.

25{
26 // Construct the full path and filename for the CSV data file.
28 std::string filename = PREFIX + method + CSV_EXTENSION;
29
30 // Open the file in append mode. Creates the file if it doesn't exist.
31 std::ofstream file(filename, std::ios::app);
32 // Write the data as a single line, comma-separated.
33 file << n << "," << m << "," << l << "," << num_nanoseconds << "," << num_repetitions << "," << min_par_compare << std::endl;
34 // File is automatically closed when 'file' goes out of scope.
35}
static const std::string CSV_EXTENSION
Standard file extension for Comma Separated Value files.
Definition data.hpp:29
static const std::string CONSTRUCTION_DATA_FILENAME
Base filename prefix for construction performance data files.
Definition data.hpp:25
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

◆ save_removal_data()

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.

Appends a record to a CSV file named based on the hostname, method, and data type. The file stores parameters and timing results for data structure removal operations.

Parameters
methodA string identifying the removal method or data structure used (e.g., "SkipTrie", "ParallelZipTrie").
nThe number of elements present before removal or the number of elements removed.
mThe characteristic length of the elements being removed (e.g., average or fixed string length).
lA parameter potentially representing the LCP or other characteristic related to the removed elements.
num_nanosecondsThe total time taken for the removal operation(s), in nanoseconds.
num_repetitionsThe number of times the removal operation was repeated or batched. Defaults to 1.
min_par_compareA parameter potentially related to parallel comparison thresholds used during removal. Defaults to 0.
is_geneticFlag indicating whether the data pertains to genetic (true) or synthetic (false) datasets. Defaults to false.

Definition at line 37 of file data.cpp.

38{
39 // Construct the full path and filename for the CSV data file.
41 std::string filename = PREFIX + method + CSV_EXTENSION;
42
43 // Open the file in append mode. Creates the file if it doesn't exist.
44 std::ofstream file(filename, std::ios::app);
45 // Write the data as a single line, comma-separated.
46 file << n << "," << m << "," << l << "," << num_nanoseconds << "," << num_repetitions << "," << min_par_compare << std::endl;
47 // File is automatically closed when 'file' goes out of scope.
48}
static const std::string REMOVAL_DATA_FILENAME
Base filename prefix for removal performance data files.
Definition data.hpp:27

◆ save_search_data()

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.

Appends a record to a CSV file named based on the hostname, method, and data type. The file stores parameters and timing results for search operations.

Parameters
methodA string identifying the search method or data structure used (e.g., "SkipTrie", "ParallelZipTrie").
nThe number of elements in the data structure when the search was performed.
mThe length of the search key (e.g., number of characters or bits).
lThe Longest Common Prefix (LCP) length between the search key and its path/result in the structure.
num_nanosecondsThe total time taken for the search operation(s), in nanoseconds.
num_repetitionsThe number of times the search operation was repeated to get the total time. Defaults to 1.
min_par_compareA parameter potentially related to parallel comparison thresholds (specific meaning depends on context). Defaults to 0.
is_geneticFlag indicating whether the data pertains to genetic (true) or synthetic (false) datasets. Defaults to false.

Definition at line 11 of file data.cpp.

12{
13 // Construct the full path and filename for the CSV data file.
15 std::string filename = PREFIX + method + CSV_EXTENSION;
16
17 // Open the file in append mode. Creates the file if it doesn't exist.
18 std::ofstream file(filename, std::ios::app);
19 // Write the data as a single line, comma-separated.
20 file << n << "," << m << "," << l << "," << num_nanoseconds << "," << num_repetitions << "," << min_par_compare << std::endl;
21 // File is automatically closed when 'file' goes out of scope.
22}
static const std::string SEARCH_DATA_FILENAME
Base filename prefix for search performance data files.
Definition data.hpp:23

Variable Documentation

◆ CONSTRUCTION_DATA_FILENAME

const std::string CONSTRUCTION_DATA_FILENAME = "construction-data-"
static

Base filename prefix for construction performance data files.

Definition at line 25 of file data.hpp.

◆ CSV_EXTENSION

const std::string CSV_EXTENSION = ".csv"
static

Standard file extension for Comma Separated Value files.

Definition at line 29 of file data.hpp.

◆ GENETIC_DATA_DIRECTORY

const std::string GENETIC_DATA_DIRECTORY = "data-genetic/"
static

Directory path for storing data related to genetic datasets.

Definition at line 19 of file data.hpp.

◆ HOSTNAME

const std::string HOSTNAME = get_hostname()
static

Constant string storing the hostname, retrieved once at program startup.

Definition at line 99 of file data.hpp.

◆ REMOVAL_DATA_FILENAME

const std::string REMOVAL_DATA_FILENAME = "removal-data-"
static

Base filename prefix for removal performance data files.

Definition at line 27 of file data.hpp.

◆ SEARCH_DATA_FILENAME

const std::string SEARCH_DATA_FILENAME = "search-data-"
static

Base filename prefix for search performance data files.

Definition at line 23 of file data.hpp.

◆ SYNTHETIC_DATA_DIRECTORY

const std::string SYNTHETIC_DATA_DIRECTORY = "data-synthetic/"
static

Directory path for storing data related to synthetic datasets.

Definition at line 21 of file data.hpp.