Skip to content

Commit

Permalink
Create benchmark_engine.cpp
Browse files Browse the repository at this point in the history
IO socketed engine to the arc-agi averages 

Signed-off-by: Josef Edwards <joed6834@colorado.edu>
  • Loading branch information
bearycool11 authored Nov 9, 2024
1 parent 100d005 commit c0cc6ad
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions benchmark_engine.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

// Define the benchmark engine class
class BenchmarkEngine {
public:
// Constructor
BenchmarkEngine();

// Destructor
~BenchmarkEngine();

// Define the benchmark function
void benchmark(const std::vector<std::string>& nodes, const std::vector<std::pair<std::string, std::string>>& edges, const std::string& query);

// Define the IO socket for benchmark output
int benchmarkSocket;

// Define the callback function for benchmark output
void benchmarkCallback(double constructionTime, double queryTime, double reasoningTime);
};

// Constructor
BenchmarkEngine::BenchmarkEngine() {
// Create the IO socket for benchmark output
benchmarkSocket = socket(AF_INET, SOCK_STREAM, 0);

// Connect to the IO socket
struct sockaddr_in server_addr;
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(8080);
inet_pton(AF_INET, "127.0.0.1", &server_addr.sin_addr);
connect(benchmarkSocket, (struct sockaddr*)&server_addr, sizeof(server_addr));
}

// Destructor
BenchmarkEngine::~BenchmarkEngine() {
// Close the IO socket
close(benchmarkSocket);
}

// Define the benchmark function
void BenchmarkEngine::benchmark(const std::vector<std::string>& nodes, const std::vector<std::pair<std::string, std::string>>& edges, const std::string& query) {
// Send the benchmark data to the IO socket
send(benchmarkSocket, &nodes, sizeof(std::vector<std::string>), 0);
send(benchmarkSocket, &edges, sizeof(std::vector<std::pair<std::string, std::string>>), 0);
send(benchmarkSocket, &query, sizeof(std::string), 0);

// Receive the benchmark results from the IO socket
double constructionTime, queryTime, reasoningTime;
recv(benchmarkSocket, &constructionTime, sizeof(double), 0);
recv(benchmarkSocket, &queryTime, sizeof(double), 0);
recv(benchmarkSocket, &reasoningTime, sizeof(double), 0);

// Print the benchmark results
std::cout << "Construction Time: " << constructionTime << std::endl;
std::cout << "Query Time: " << queryTime << std::endl;
std::cout << "Reasoning Time: " << reasoningTime << std::endl;
}

// Define the callback function for benchmark output
void BenchmarkEngine::benchmarkCallback(double constructionTime, double queryTime, double reasoningTime) {
// Send the benchmark results to the IO socket
send(benchmarkSocket, &constructionTime, sizeof(double), 0);
send(benchmarkSocket, &queryTime, sizeof(double), 0);
send(benchmarkSocket, &reasoningTime, sizeof(double), 0);
}

int main() {
// Create a benchmark engine object
BenchmarkEngine benchmarkEngine;

// Define the knowledge graph construction algorithm
std::vector<std::string> nodes = {"node1", "node2", "node3"};
std::vector<std::pair<std::string, std::string>> edges = {{"node1", "node2"}, {"

1 comment on commit c0cc6ad

@bearycool11
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$1 million prize solution to the arc-agi benchmark, for Francois.

Please sign in to comment.