Basic benchmark command
This commit is contained in:
parent
a7d076ec80
commit
a535ce5283
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,6 +2,7 @@
|
|||||||
.venv
|
.venv
|
||||||
ZipponDB
|
ZipponDB
|
||||||
data
|
data
|
||||||
|
benchmark
|
||||||
engine
|
engine
|
||||||
engine.o
|
engine.o
|
||||||
zig-out
|
zig-out
|
||||||
|
21
build.zig
21
build.zig
@ -25,7 +25,8 @@ pub fn build(b: *std.Build) void {
|
|||||||
const run_step = b.step("run", "Run the app");
|
const run_step = b.step("run", "Run the app");
|
||||||
run_step.dependOn(&run_cmd.step);
|
run_step.dependOn(&run_cmd.step);
|
||||||
|
|
||||||
// All tests
|
// Test
|
||||||
|
// -----------------------------------------------
|
||||||
const tests1 = b.addTest(.{
|
const tests1 = b.addTest(.{
|
||||||
.root_source_file = b.path("src/stuffs/UUIDFileIndex.zig"),
|
.root_source_file = b.path("src/stuffs/UUIDFileIndex.zig"),
|
||||||
.target = target,
|
.target = target,
|
||||||
@ -93,4 +94,22 @@ pub fn build(b: *std.Build) void {
|
|||||||
test_step.dependOn(&run_tests4.step);
|
test_step.dependOn(&run_tests4.step);
|
||||||
test_step.dependOn(&run_tests5.step);
|
test_step.dependOn(&run_tests5.step);
|
||||||
test_step.dependOn(&run_tests6.step);
|
test_step.dependOn(&run_tests6.step);
|
||||||
|
|
||||||
|
// Benchmark
|
||||||
|
// -----------------------------------------------
|
||||||
|
const benchmark = b.addExecutable(.{
|
||||||
|
.name = "benchmark",
|
||||||
|
.root_source_file = b.path("src/benchmark.zig"),
|
||||||
|
.target = target,
|
||||||
|
.optimize = optimize,
|
||||||
|
});
|
||||||
|
benchmark.root_module.addImport("dtype", b.createModule(.{ .root_source_file = b.path("lib/types/out.zig") }));
|
||||||
|
benchmark.root_module.addImport("ZipponData", b.createModule(.{ .root_source_file = b.path("lib/zid.zig") }));
|
||||||
|
b.installArtifact(benchmark);
|
||||||
|
|
||||||
|
const run_benchmark = b.addRunArtifact(benchmark);
|
||||||
|
run_benchmark.step.dependOn(b.getInstallStep());
|
||||||
|
|
||||||
|
const benchmark_step = b.step("benchmark", "Run benchmarks");
|
||||||
|
benchmark_step.dependOn(&run_benchmark.step);
|
||||||
}
|
}
|
||||||
|
77
src/benchmark.zig
Normal file
77
src/benchmark.zig
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
const std = @import("std");
|
||||||
|
const DBEngine = @import("main.zig").DBEngine;
|
||||||
|
const dtype = @import("dtype");
|
||||||
|
const ziqlTokenizer = @import("tokenizers/ziql.zig").Tokenizer;
|
||||||
|
const ziqlToken = @import("tokenizers/ziql.zig").Token;
|
||||||
|
const ziqlParser = @import("ziqlParser.zig").Parser;
|
||||||
|
|
||||||
|
pub const std_options = .{
|
||||||
|
.logFn = myLog,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn myLog(
|
||||||
|
comptime message_level: std.log.Level,
|
||||||
|
comptime scope: @Type(.EnumLiteral),
|
||||||
|
comptime format: []const u8,
|
||||||
|
args: anytype,
|
||||||
|
) void {
|
||||||
|
if (true) return;
|
||||||
|
_ = message_level;
|
||||||
|
_ = scope;
|
||||||
|
_ = format;
|
||||||
|
_ = args;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn main() !void {
|
||||||
|
var line_buffer: [1024 * 1024]u8 = undefined;
|
||||||
|
// Initialize your DBEngine here
|
||||||
|
var db_engine = DBEngine.init("benchmark", "example.zipponschema");
|
||||||
|
defer db_engine.deinit();
|
||||||
|
|
||||||
|
// Define your benchmark queries
|
||||||
|
const populate = [_][]const u8{
|
||||||
|
"ADD User (name = 'Bob', email='bob@email.com', age=55, scores=[ 1 ], best_friend=none, friends=none, bday=2000/01/01, a_time=12:04, last_order=2000/01/01-12:45)",
|
||||||
|
};
|
||||||
|
|
||||||
|
// Run benchmarks
|
||||||
|
const populate_start_time = std.time.nanoTimestamp();
|
||||||
|
for (populate) |query| {
|
||||||
|
const null_term_query_str = try std.fmt.bufPrintZ(&line_buffer, "{s}", .{query});
|
||||||
|
for (0..1) |_| {
|
||||||
|
var toker = ziqlTokenizer.init(null_term_query_str);
|
||||||
|
var parser = ziqlParser.init(&toker, &db_engine.file_engine, &db_engine.schema_engine);
|
||||||
|
try parser.parse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const populate_end_time = std.time.nanoTimestamp();
|
||||||
|
const populate_duration = @as(f64, @floatFromInt(populate_end_time - populate_start_time)) / 1e9;
|
||||||
|
|
||||||
|
std.debug.print("Populate duration: {d:.6} seconds\n\n", .{populate_duration});
|
||||||
|
|
||||||
|
// Define your benchmark queries
|
||||||
|
const queries = [_][]const u8{
|
||||||
|
"GRAB User {}",
|
||||||
|
"GRAB User [1] {}",
|
||||||
|
"GRAB User [name] {}",
|
||||||
|
"GRAB User {name = 'Adrien'}",
|
||||||
|
"GRAB User {age > 30}",
|
||||||
|
};
|
||||||
|
|
||||||
|
// Run benchmarks
|
||||||
|
std.debug.print("Running benchmarks...\n", .{});
|
||||||
|
for (queries) |query| {
|
||||||
|
const start_time = std.time.nanoTimestamp();
|
||||||
|
|
||||||
|
// Execute the query here
|
||||||
|
const null_term_query_str = try std.fmt.bufPrintZ(&line_buffer, "{s}", .{query});
|
||||||
|
var toker = ziqlTokenizer.init(null_term_query_str);
|
||||||
|
var parser = ziqlParser.init(&toker, &db_engine.file_engine, &db_engine.schema_engine);
|
||||||
|
try parser.parse();
|
||||||
|
|
||||||
|
const end_time = std.time.nanoTimestamp();
|
||||||
|
const duration = @as(f64, @floatFromInt(end_time - start_time)) / 1e9;
|
||||||
|
|
||||||
|
std.debug.print("Query: {s}\nDuration: {d:.6} seconds\n\n", .{ query, duration });
|
||||||
|
}
|
||||||
|
}
|
@ -56,6 +56,8 @@ pub fn myLog(
|
|||||||
comptime format: []const u8,
|
comptime format: []const u8,
|
||||||
args: anytype,
|
args: anytype,
|
||||||
) void {
|
) void {
|
||||||
|
if (true) return;
|
||||||
|
|
||||||
const level_txt = comptime message_level.asText();
|
const level_txt = comptime message_level.asText();
|
||||||
const prefix = if (scope == .default) " - " else "(" ++ @tagName(scope) ++ ") - ";
|
const prefix = if (scope == .default) " - " else "(" ++ @tagName(scope) ++ ") - ";
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ const stdout = std.io.getStdOut().writer();
|
|||||||
|
|
||||||
// Maybe create a struct for that
|
// Maybe create a struct for that
|
||||||
pub fn send(comptime format: []const u8, args: anytype) void {
|
pub fn send(comptime format: []const u8, args: anytype) void {
|
||||||
if (false) return;
|
if (true) return;
|
||||||
|
|
||||||
stdout.print(format, args) catch |err| {
|
stdout.print(format, args) catch |err| {
|
||||||
log.err("Can't send: {any}", .{err});
|
log.err("Can't send: {any}", .{err});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user