Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Benchmark and optimization #223

Merged
merged 3 commits into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .gitmodules
Empty file.
10 changes: 4 additions & 6 deletions benchmark/BFS_BM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
#include "CXXGraph.hpp"
#include "Utilities.hpp"

static auto nodes = generateRandomNodes(100000, 2);
static auto edges = generateRandomEdges(100000, nodes);
static auto graph_ptr = readGraph("CitHepPh");

static void BFS_X(benchmark::State &state)
{
Expand All @@ -26,12 +23,13 @@ BENCHMARK(BFS_X)->RangeMultiplier(16)->Range((unsigned long)1, (unsigned long)1

static void BFS_FromReadedCitHep(benchmark::State &state)
{
auto edgeSet = graph_ptr->getEdgeSet();
auto edgeSet = cit_graph_ptr->getEdgeSet();
for (auto _ : state)
{

auto &result = graph_ptr->breadth_first_search(*((*(edgeSet.begin()))->getNodePair().first));
auto &result = cit_graph_ptr->breadth_first_search(*((*(edgeSet.begin()))->getNodePair().first));
}
}

BENCHMARK(BFS_FromReadedCitHep);
BENCHMARK(BFS_FromReadedCitHep);

34 changes: 34 additions & 0 deletions benchmark/BellmanFord_BM.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <benchmark/benchmark.h>
#include "CXXGraph.hpp"
#include "Utilities.hpp"


static void BellmanFord_X(benchmark::State &state)
{
CXXGRAPH::Graph<int> g;
auto range_start = edges.begin();
auto range_end = edges.find(state.range(0));
std::unordered_map<unsigned long, CXXGRAPH::Edge<int> *> edgesX;
edgesX.insert(range_start, range_end);
for (auto e : edgesX)
{
g.addEdge(&(*e.second));
}
for (auto _ : state)
{
auto &result = g.bellmanford(*(range_start->second->getNodePair().first), *(range_end->second->getNodePair().second));
}
}
BENCHMARK(BellmanFord_X)->RangeMultiplier(16)->Range((unsigned long)1, (unsigned long)1 << 16);

static void BellmanFord_FromReadedCitHep(benchmark::State &state)
{
auto edgeSet = cit_graph_ptr->getEdgeSet();
for (auto _ : state)
{

auto &result = cit_graph_ptr->bellmanford(*((*(edgeSet.begin()))->getNodePair().first), *((*(++edgeSet.begin()))->getNodePair().second));
}
}

BENCHMARK(BellmanFord_FromReadedCitHep);
34 changes: 34 additions & 0 deletions benchmark/Boruvka_BM.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <benchmark/benchmark.h>
#include "CXXGraph.hpp"
#include "Utilities.hpp"


static void Boruvka_X(benchmark::State &state)
{
CXXGRAPH::Graph<int> g;
auto range_start = edges.begin();
auto range_end = edges.find(state.range(0));
std::unordered_map<unsigned long, CXXGRAPH::Edge<int> *> edgesX;
edgesX.insert(range_start, range_end);
for (auto e : edgesX)
{
g.addEdge(&(*e.second));
}
for (auto _ : state)
{
auto &result = g.boruvka();
}
}
BENCHMARK(Boruvka_X)->RangeMultiplier(16)->Range((unsigned long)1, (unsigned long)1 << 16);

static void Boruvka_FromReadedCitHep(benchmark::State &state)
{
auto edgeSet = cit_graph_ptr->getEdgeSet();
for (auto _ : state)
{

auto &result = cit_graph_ptr->boruvka();
}
}

BENCHMARK(Boruvka_FromReadedCitHep);
64 changes: 64 additions & 0 deletions benchmark/Connectivity_BM.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include <benchmark/benchmark.h>
#include "CXXGraph.hpp"
#include "Utilities.hpp"


static void Connectivity_X(benchmark::State &state)
{
CXXGRAPH::Graph<int> g;
auto range_start = edges.begin();
auto range_end = edges.find(state.range(0));
std::unordered_map<unsigned long, CXXGRAPH::Edge<int> *> edgesX;
edgesX.insert(range_start, range_end);
for (auto e : edgesX)
{
g.addEdge(&(*e.second));
}
for (auto _ : state)
{
auto result = g.isConnectedGraph();
}
}
BENCHMARK(Connectivity_X)->RangeMultiplier(16)->Range((unsigned long)1, (unsigned long)1 << 16);

static void Connectivity_FromReadedCitHep(benchmark::State &state)
{
auto edgeSet = cit_graph_ptr->getEdgeSet();
for (auto _ : state)
{

auto result = cit_graph_ptr->isConnectedGraph();
}
}

BENCHMARK(Connectivity_FromReadedCitHep);

static void StrongConnectivity_X(benchmark::State &state)
{
CXXGRAPH::Graph<int> g;
auto range_start = edges.begin();
auto range_end = edges.find(state.range(0));
std::unordered_map<unsigned long, CXXGRAPH::Edge<int> *> edgesX;
edgesX.insert(range_start, range_end);
for (auto e : edgesX)
{
g.addEdge(&(*e.second));
}
for (auto _ : state)
{
auto result = g.isConnectedGraph();
}
}
BENCHMARK(StrongConnectivity_X)->RangeMultiplier(16)->Range((unsigned long)1, (unsigned long)1 << 16);

static void StrongConnectivity_FromReadedCitHep(benchmark::State &state)
{
auto edgeSet = cit_graph_ptr->getEdgeSet();
for (auto _ : state)
{

auto result = cit_graph_ptr->isConnectedGraph();
}
}

BENCHMARK(StrongConnectivity_FromReadedCitHep);
64 changes: 64 additions & 0 deletions benchmark/CycleCheck_BM.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include <benchmark/benchmark.h>
#include "CXXGraph.hpp"
#include "Utilities.hpp"


static void CycleCheckBFS_X(benchmark::State &state)
{
CXXGRAPH::Graph<int> g;
auto range_start = edges.begin();
auto range_end = edges.find(state.range(0));
std::unordered_map<unsigned long, CXXGRAPH::Edge<int> *> edgesX;
edgesX.insert(range_start, range_end);
for (auto e : edgesX)
{
g.addEdge(&(*e.second));
}
for (auto _ : state)
{
auto result = g.isCyclicDirectedGraphBFS();
}
}
BENCHMARK(CycleCheckBFS_X)->RangeMultiplier(16)->Range((unsigned long)1, (unsigned long)1 << 16);

static void CycleCheckBFS_FromReadedCitHep(benchmark::State &state)
{
auto edgeSet = cit_graph_ptr->getEdgeSet();
for (auto _ : state)
{

auto result = cit_graph_ptr->isCyclicDirectedGraphBFS();
}
}

BENCHMARK(CycleCheckBFS_FromReadedCitHep);

static void CycleCheckDFS_X(benchmark::State &state)
{
CXXGRAPH::Graph<int> g;
auto range_start = edges.begin();
auto range_end = edges.find(state.range(0));
std::unordered_map<unsigned long, CXXGRAPH::Edge<int> *> edgesX;
edgesX.insert(range_start, range_end);
for (auto e : edgesX)
{
g.addEdge(&(*e.second));
}
for (auto _ : state)
{
auto result = g.isCyclicDirectedGraphDFS();
}
}
BENCHMARK(CycleCheckDFS_X)->RangeMultiplier(16)->Range((unsigned long)1, (unsigned long)1 << 16);

static void CycleCheckDFS_FromReadedCitHep(benchmark::State &state)
{
auto edgeSet = cit_graph_ptr->getEdgeSet();
for (auto _ : state)
{

auto result = cit_graph_ptr->isCyclicDirectedGraphDFS();
}
}

BENCHMARK(CycleCheckDFS_FromReadedCitHep);
10 changes: 4 additions & 6 deletions benchmark/DFS_BM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
#include "CXXGraph.hpp"
#include "Utilities.hpp"

static auto nodes = generateRandomNodes(100000, 2);
static auto edges = generateRandomEdges(100000, nodes);
static auto graph_ptr = readGraph("CitHepPh");

static void DFS_X(benchmark::State &state)
{
Expand All @@ -28,12 +25,13 @@ BENCHMARK(DFS_X)->RangeMultiplier(16)->Range((unsigned long)1, (unsigned long)1

static void DFS_FromReadedCitHep(benchmark::State &state)
{
auto edgeSet = graph_ptr->getEdgeSet();
auto edgeSet = cit_graph_ptr->getEdgeSet();
for (auto _ : state)
{

auto &result = graph_ptr->depth_first_search(*((*(edgeSet.begin()))->getNodePair().first));
auto &result = cit_graph_ptr->depth_first_search(*((*(edgeSet.begin()))->getNodePair().first));
}
}

BENCHMARK(DFS_FromReadedCitHep);
BENCHMARK(DFS_FromReadedCitHep);

33 changes: 33 additions & 0 deletions benchmark/Dial_BM.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <benchmark/benchmark.h>
#include "CXXGraph.hpp"
#include "Utilities.hpp"

static void Dial_X(benchmark::State &state)
{
CXXGRAPH::Graph<int> g;
auto range_start = edges.begin();
auto range_end = edges.find(state.range(0));
std::unordered_map<unsigned long, CXXGRAPH::Edge<int> *> edgesX;
edgesX.insert(range_start, range_end);
for (auto e : edgesX)
{
g.addEdge(&(*e.second));
}
for (auto _ : state)
{
auto &result = g.dial(*(range_start->second->getNodePair().first),1);
}
}
BENCHMARK(Dial_X)->RangeMultiplier(16)->Range((unsigned long)1, (unsigned long)1 << 16);

static void Dial_FromReadedCitHep(benchmark::State &state)
{
auto edgeSet = cit_graph_ptr->getEdgeSet();
for (auto _ : state)
{

auto &result = cit_graph_ptr->dial(*((*(edgeSet.begin()))->getNodePair().first), 1);
}
}

BENCHMARK(Dial_FromReadedCitHep);
35 changes: 35 additions & 0 deletions benchmark/Dijkstra_BM.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <benchmark/benchmark.h>
#include "CXXGraph.hpp"
#include "Utilities.hpp"


static void Dijkstra_X(benchmark::State &state)
{
CXXGRAPH::Graph<int> g;
auto range_start = edges.begin();
auto range_end = edges.find(state.range(0));
std::unordered_map<unsigned long, CXXGRAPH::Edge<int> *> edgesX;
edgesX.insert(range_start, range_end);
for (auto e : edgesX)
{
g.addEdge(&(*e.second));
}
for (auto _ : state)
{
auto &result = g.dijkstra(*(range_start->second->getNodePair().first), *(range_end->second->getNodePair().second));
}
}
BENCHMARK(Dijkstra_X)->RangeMultiplier(16)->Range((unsigned long)1, (unsigned long)1 << 16);

static void Dijkstra_FromReadedCitHep(benchmark::State &state)
{
auto edgeSet = cit_graph_ptr->getEdgeSet();
for (auto _ : state)
{

auto &result = cit_graph_ptr->dijkstra(*((*(edgeSet.begin()))->getNodePair().first),*((*(++edgeSet.begin()))->getNodePair().second));
}
}

BENCHMARK(Dijkstra_FromReadedCitHep);

22 changes: 22 additions & 0 deletions benchmark/EulerPath_BM.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <benchmark/benchmark.h>
#include "CXXGraph.hpp"
#include "Utilities.hpp"


static void EulerPath_X(benchmark::State &state)
{
CXXGRAPH::Graph<int> g;
auto range_start = undirectedEdges.begin();
auto range_end = undirectedEdges.find(state.range(0));
std::unordered_map<unsigned long, CXXGRAPH::Edge<int> *> edgesX;
edgesX.insert(range_start, range_end);
for (auto e : edgesX)
{
g.addEdge(&(*e.second));
}
for (auto _ : state)
{
auto result = g.eulerianPath();
}
}
BENCHMARK(EulerPath_X)->RangeMultiplier(16)->Range((unsigned long)1, (unsigned long)1 << 16);
8 changes: 4 additions & 4 deletions benchmark/FloydWarshall_BM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static void BM_FWDirected(benchmark::State &state)
CXXGRAPH::DirectedWeightedEdge<int> edge4(4, node4, node2, -1);
CXXGRAPH::DirectedWeightedEdge<int> edge5(3, node2, node3, 3);

std::set<const CXXGRAPH::Edge<int> *> edgeSet;
CXXGRAPH::T_EdgeSet<int> edgeSet;
edgeSet.insert(&edge1);
edgeSet.insert(&edge2);
edgeSet.insert(&edge3);
Expand All @@ -40,7 +40,7 @@ static void BM_FWNegCycle(benchmark::State &state)
CXXGRAPH::DirectedWeightedEdge<int> edge1(1, node0, node1, 2);
CXXGRAPH::DirectedWeightedEdge<int> edge2(2, node1, node2, 3);
CXXGRAPH::DirectedWeightedEdge<int> edge3(3, node2, node0, -7);
std::set<const CXXGRAPH::Edge<int> *> edgeSet;
CXXGRAPH::T_EdgeSet<int> edgeSet;
edgeSet.insert(&edge1);
edgeSet.insert(&edge2);
edgeSet.insert(&edge3);
Expand All @@ -61,7 +61,7 @@ static void BM_FWUndirectedWeighted(benchmark::State &state)
CXXGRAPH::DirectedWeightedEdge<int> edge1(1, pairNode, 1);
CXXGRAPH::DirectedWeightedEdge<int> edge2(2, node2, node3, 1);
CXXGRAPH::UndirectedWeightedEdge<int> edge3(3, node1, node3, 6);
std::set<const CXXGRAPH::Edge<int> *> edgeSet;
CXXGRAPH::T_EdgeSet<int> edgeSet;
edgeSet.insert(&edge1);
edgeSet.insert(&edge2);
edgeSet.insert(&edge3);
Expand All @@ -82,7 +82,7 @@ static void BM_FWNoWeighted(benchmark::State &state)
CXXGRAPH::DirectedWeightedEdge<int> edge1(1, pairNode, 1);
CXXGRAPH::DirectedWeightedEdge<int> edge2(2, node2, node3, 1);
CXXGRAPH::DirectedEdge<int> edge3(3, node1, node3);
std::set<const CXXGRAPH::Edge<int> *> edgeSet;
CXXGRAPH::T_EdgeSet<int> edgeSet;
edgeSet.insert(&edge1);
edgeSet.insert(&edge2);
edgeSet.insert(&edge3);
Expand Down
Loading