Add benchmark
This commit is contained in:
174
benchmark/algorithm_bench.cc
Normal file
174
benchmark/algorithm_bench.cc
Normal file
@@ -0,0 +1,174 @@
|
||||
#include <src/include/nanobench.h>
|
||||
#include <doctest/doctest.h>
|
||||
|
||||
#include "algorithm/king.h"
|
||||
#include "algorithm/henzinger_king.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <random>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
using namespace graph;
|
||||
|
||||
TEST_CASE("Italiano and King inspired algorithms") {
|
||||
std::ifstream fdag{ "resources/dag.txt" };
|
||||
int u;
|
||||
int v;
|
||||
Digraph<int> G;
|
||||
std::vector<std::pair<int, int>> graphVertices;
|
||||
std::vector<std::pair<int, int>> graphVerticesReverse;
|
||||
|
||||
while (fdag >> u >> v) {
|
||||
G.insert(u, v);
|
||||
graphVertices.push_back(std::make_pair(u, v));
|
||||
graphVerticesReverse.push_back(std::make_pair(v, u));
|
||||
}
|
||||
|
||||
auto italiano = std::make_unique<algo::Italiano<int>>(G);
|
||||
italiano->init();
|
||||
|
||||
auto king = std::make_unique<algo::King<int>>(G);
|
||||
king->init();
|
||||
|
||||
ankerl::nanobench::Rng rng;
|
||||
rng.shuffle(graphVertices);
|
||||
|
||||
std::vector<std::pair<int, int>> graphVerticesDeleteSubset(graphVertices.begin(), graphVertices.begin() + 25);
|
||||
std::vector<std::pair<int, int>> graphVerticesQuerySubset(graphVerticesReverse.begin() + 50, graphVerticesReverse.begin() + 75);
|
||||
|
||||
// Deleting Phase
|
||||
|
||||
ankerl::nanobench::Bench()
|
||||
.epochs(1)
|
||||
.run("Italiano::remove",
|
||||
[&italiano, graphVerticesDeleteSubset] {
|
||||
italiano->remove(graphVerticesDeleteSubset);
|
||||
});
|
||||
|
||||
ankerl::nanobench::Bench()
|
||||
.epochs(1)
|
||||
.run("King::remove",
|
||||
[&king, graphVerticesDeleteSubset] {
|
||||
king->remove(graphVerticesDeleteSubset);
|
||||
});
|
||||
|
||||
ankerl::nanobench::Bench()
|
||||
.epochs(1)
|
||||
.run("Simple::remove(DAG)",
|
||||
[&G, graphVerticesDeleteSubset] {
|
||||
for (const auto& [w, z] : graphVerticesDeleteSubset) {
|
||||
G.remove(w, z);
|
||||
}
|
||||
});
|
||||
|
||||
// Querying Phase
|
||||
|
||||
ankerl::nanobench::Bench()
|
||||
.epochs(1)
|
||||
.run("Italiano::query",
|
||||
[&italiano, graphVerticesQuerySubset] {
|
||||
for (const auto& [w, z] : graphVerticesQuerySubset) {
|
||||
ankerl::nanobench::doNotOptimizeAway(italiano->query(w, z));
|
||||
}
|
||||
});
|
||||
|
||||
ankerl::nanobench::Bench()
|
||||
.epochs(1)
|
||||
.run("King::query",
|
||||
[&king, graphVerticesQuerySubset] {
|
||||
for (const auto& [w, z] : graphVerticesQuerySubset) {
|
||||
ankerl::nanobench::doNotOptimizeAway(king->query(w, z));
|
||||
}
|
||||
});
|
||||
|
||||
ankerl::nanobench::Bench()
|
||||
.epochs(1)
|
||||
.run("Simple::query(DAG)",
|
||||
[&G, graphVerticesQuerySubset] {
|
||||
for (const auto& [w, z] : graphVerticesQuerySubset) {
|
||||
ankerl::nanobench::doNotOptimizeAway(G.contains(w, z));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
TEST_CASE("Frigioni and Henzinger/King inspired algorithms") {
|
||||
std::ifstream fgeneral{ "resources/general.txt" };
|
||||
int u;
|
||||
int v;
|
||||
Digraph<int> G;
|
||||
std::vector<std::pair<int, int>> graphVertices;
|
||||
std::vector<std::pair<int, int>> graphVerticesReverse;
|
||||
|
||||
while (fgeneral >> u >> v) {
|
||||
G.insert(u, v);
|
||||
graphVertices.push_back(std::make_pair(u, v));
|
||||
graphVerticesReverse.push_back(std::make_pair(v, u));
|
||||
}
|
||||
|
||||
auto frigioni = std::make_unique<algo::Frigioni<int>>(G);
|
||||
frigioni->init();
|
||||
|
||||
auto henzingerKing = std::make_unique<algo::HenzingerKing<int>>(G);
|
||||
henzingerKing->init();
|
||||
|
||||
ankerl::nanobench::Rng rng;
|
||||
rng.shuffle(graphVertices);
|
||||
|
||||
std::vector<std::pair<int, int>> graphVerticesDeleteSubset(graphVertices.begin(), graphVertices.begin() + 25);
|
||||
std::vector<std::pair<int, int>> graphVerticesQuerySubset(graphVerticesReverse.begin() + 50, graphVerticesReverse.begin() + 75);
|
||||
|
||||
// Deleting Phase
|
||||
|
||||
ankerl::nanobench::Bench()
|
||||
.epochs(1)
|
||||
.run("Frigioni::remove",
|
||||
[&frigioni, graphVerticesDeleteSubset] {
|
||||
frigioni->remove(graphVerticesDeleteSubset);
|
||||
});
|
||||
|
||||
ankerl::nanobench::Bench()
|
||||
.epochs(1)
|
||||
.run("HenzingerKing::remove",
|
||||
[&henzingerKing, graphVerticesDeleteSubset] {
|
||||
henzingerKing->remove(graphVerticesDeleteSubset);
|
||||
});
|
||||
|
||||
ankerl::nanobench::Bench()
|
||||
.epochs(1)
|
||||
.run("Simple::remove(General)",
|
||||
[&G, graphVerticesDeleteSubset] {
|
||||
for (const auto& [w, z] : graphVerticesDeleteSubset) {
|
||||
G.remove(w, z);
|
||||
}
|
||||
});
|
||||
|
||||
// Querying Phase
|
||||
|
||||
ankerl::nanobench::Bench()
|
||||
.epochs(1)
|
||||
.run("Frigioni::query",
|
||||
[&frigioni, graphVerticesQuerySubset] {
|
||||
for (const auto& [w, z] : graphVerticesQuerySubset) {
|
||||
ankerl::nanobench::doNotOptimizeAway(frigioni->query(w, z));
|
||||
}
|
||||
});
|
||||
|
||||
ankerl::nanobench::Bench()
|
||||
.epochs(1)
|
||||
.run("HenzingerKing::query",
|
||||
[&henzingerKing, graphVerticesQuerySubset] {
|
||||
for (const auto& [w, z] : graphVerticesQuerySubset) {
|
||||
ankerl::nanobench::doNotOptimizeAway(henzingerKing->query(w, z));
|
||||
}
|
||||
});
|
||||
|
||||
ankerl::nanobench::Bench()
|
||||
.epochs(1)
|
||||
.run("Simple::query(General)",
|
||||
[&G, graphVerticesQuerySubset] {
|
||||
for (const auto& [w, z] : graphVerticesQuerySubset) {
|
||||
ankerl::nanobench::doNotOptimizeAway(G.contains(w, z));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
#include <src/include/nanobench.h>
|
||||
#include <doctest/doctest.h>
|
||||
|
||||
using namespace graph;
|
||||
|
||||
TEST_SUITE("Decremental Reachability Bench") {
|
||||
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
#include <src/include/nanobench.h>
|
||||
#include <doctest/doctest.h>
|
||||
|
||||
#include "algorithm/king.h"
|
||||
#include "algorithm/henzinger_king.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <random>
|
||||
#include <fstream>
|
||||
|
||||
using namespace graph;
|
||||
|
||||
TEST_SUITE("Dynamic Reachability Bench") {
|
||||
ankerl::nanobench::Bench dynBench;
|
||||
|
||||
TEST_CASE("King") {
|
||||
std::ifstream fgeneral{ "resources/dag.txt" };
|
||||
std::vector<std::pair<int, int>> dagGraph;
|
||||
int fu, fv;
|
||||
|
||||
while (fgeneral >> fu >> fv)
|
||||
dagGraph.push_back({ fu, fv });
|
||||
|
||||
graph::Digraph<int> G;
|
||||
for (const auto& [u, v] : dagGraph)
|
||||
G.insert(u, v);
|
||||
|
||||
algo::King<int>* k = new algo::King(G);
|
||||
k->init();
|
||||
|
||||
std::random_device rd;
|
||||
std::mt19937 mt(rd());
|
||||
std::ranges::shuffle(dagGraph, mt);
|
||||
std::vector<std::pair<int, int>> delEdges(dagGraph.begin(),
|
||||
dagGraph.begin() + 20);
|
||||
|
||||
dynBench.epochs(1).run("K::remove", [&] {
|
||||
k->remove(delEdges); }
|
||||
);
|
||||
|
||||
std::uniform_int_distribution<> dist(1, 200);
|
||||
|
||||
dynBench.epochs(1).run("K::query", [&] {
|
||||
for (int i = 0; i < 50; ++i)
|
||||
k->query(dist(mt), dist(mt)); }
|
||||
);
|
||||
|
||||
std::vector<int> insEdges;
|
||||
for (int i = 0; i < 50; ++i)
|
||||
insEdges.push_back(dist(mt));
|
||||
|
||||
dynBench.epochs(1).run("K::insert", [&] {
|
||||
k->insert(50, insEdges); }
|
||||
);
|
||||
}
|
||||
|
||||
TEST_CASE("HenzingerKing") {
|
||||
std::ifstream fgeneral{ "resources/general.txt" };
|
||||
std::vector<std::pair<int, int>> generalGraph;
|
||||
int fu, fv;
|
||||
|
||||
while (fgeneral >> fu >> fv)
|
||||
generalGraph.push_back({ fu, fv });
|
||||
|
||||
graph::Digraph<int> G;
|
||||
for (const auto& [u, v] : generalGraph)
|
||||
G.insert(u, v);
|
||||
|
||||
algo::HenzingerKing<int>* hk = new algo::HenzingerKing(G);
|
||||
hk->init();
|
||||
|
||||
std::random_device rd;
|
||||
std::mt19937 mt(rd());
|
||||
std::ranges::shuffle(generalGraph, mt);
|
||||
std::vector<std::pair<int, int>> delEdges(generalGraph.begin(),
|
||||
generalGraph.begin() + 20);
|
||||
|
||||
dynBench.epochs(1).run("HK::remove", [&] {
|
||||
hk->remove(delEdges); }
|
||||
);
|
||||
|
||||
std::uniform_int_distribution<> dist(1, 200);
|
||||
|
||||
dynBench.epochs(1).run("HK::query", [&] {
|
||||
for (int i = 0; i < 50; ++i)
|
||||
hk->query(dist(mt), dist(mt)); }
|
||||
);
|
||||
|
||||
std::vector<int> insEdges;
|
||||
for (int i = 0; i < 50; ++i)
|
||||
insEdges.push_back(dist(mt));
|
||||
|
||||
dynBench.epochs(1).run("HK::insert", [&] {
|
||||
hk->insert(50, insEdges); }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user