Skip to content

Commit

Permalink
Update benchmark_engine.cpp
Browse files Browse the repository at this point in the history
Signed-off-by: Josef Edwards <joed6834@colorado.edu>
  • Loading branch information
bearycool11 authored Nov 10, 2024
1 parent 4d9bbd1 commit f5f9d0c
Showing 1 changed file with 66 additions and 74 deletions.
140 changes: 66 additions & 74 deletions benchmark_engine.cpp
Original file line number Diff line number Diff line change
@@ -1,77 +1,69 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "json.h"

// Define the JSON object structure
typedef struct {
char* benchmark_name;
char* benchmark_version;
struct {
char* metric_name;
double value;
char* units;
} results[3];
} BenchmarkResults;

// Define the function to generate the JSON output
void generate_json_output(BenchmarkResults* results) {
// Create a JSON object
json_t* json = json_object();

// Add the benchmark name and version to the JSON object
json_object_set(json, "benchmark_name", json_string(results->benchmark_name));
json_object_set(json, "benchmark_version", json_string(results->benchmark_version));

// Add the results array to the JSON object
json_t* results_array = json_array();
for (int i = 0; i < 3; i++) {
json_t* result = json_object();
json_object_set(result, "metric_name", json_string(results->results[i].metric_name));
json_object_set(result, "value", json_real(results->results[i].value));
json_object_set(result, "units", json_string(results->results[i].units));
json_array_append(results_array, result);
// Define the buffer size
#define BUFFER_SIZE 1024

// Define the chunk size
#define CHUNK_SIZE 256

// Define the buffer
char buffer[BUFFER_SIZE];

// Define the chunk
char chunk[CHUNK_SIZE];

// Define the JSON object
json_t* json;

// Define the error variable
int error;

// Create a socket to listen for incoming connections
int sock = socket(AF_INET, SOCK_STREAM, 0);

// Define the server address
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);

// Bind the socket to the server address
bind(sock, (struct sockaddr*)&server_addr, sizeof(server_addr));

// Listen for incoming connections
listen(sock, 1);

// Accept an incoming connection
int client_sock = accept(sock, NULL, NULL);

// Receive the JSON string from the client in chunks
while (1) {
// Receive a chunk of data from the client
int bytes_received = recv(client_sock, chunk, CHUNK_SIZE, 0);

// Check if the chunk is empty
if (bytes_received == 0) {
break;
}
json_object_set(json, "results", results_array);

// Convert the JSON object to a string
char* json_string = json_dumps(json, 0);

// Send the JSON string over the socket
int sock = socket(AF_INET, SOCK_STREAM, 0);
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(sock, (struct sockaddr*)&server_addr, sizeof(server_addr));
send(sock, json_string, strlen(json_string), 0);
close(sock);

// Free the JSON object and string
json_decref(json);
free(json_string);
}

int main() {
// Define the benchmark results
BenchmarkResults results;
results.benchmark_name = "Arc-AGI";
results.benchmark_version = "1.0";
results.results[0].metric_name = "construction_time";
results.results[0].value = 0.123;
results.results[0].units = "seconds";
results.results[1].metric_name = "query_time";
results.results[1].value = 0.456;
results.results[1].units = "seconds";
results.results[2].metric_name = "reasoning_time";
results.results[2].value = 0.789;
results.results[2].units = "seconds";

// Generate the JSON output
generate_json_output(&results);

return 0;
// Append the chunk to the buffer
strcat(buffer, chunk);

// Validate the chunk
json = json_loads(buffer, 0, &error);

// Check for errors
if (error != 0) {
// Handle the error
printf("Error parsing JSON: %s\n", json_error_string(error));
return 1;
}

// Write the chunk to the knowledge graph
// ...
}

// Close the socket
close(client_sock);
close(sock);

// Free the JSON object
json_decref(json);

0 comments on commit f5f9d0c

Please sign in to comment.