Update benchmark and some stuff

This commit is contained in:
Adrien Bouvais 2025-01-11 19:26:06 +01:00
parent 13caff2fd7
commit bc0c0cbe1d
4 changed files with 120 additions and 75 deletions

2
.gitignore vendored
View File

@ -6,3 +6,5 @@ benchmark
engine
engine.o
zig-out
test1
test2

View File

@ -31,12 +31,19 @@ pub fn myLog(
}
pub fn main() !void {
const to_test = [_]usize{50_000};
const to_test = [_]usize{500};
{
var line_buffer: [1024 * 1024]u8 = undefined;
var db_engine = DBEngine.init("benchmark", "schema/example");
defer db_engine.deinit();
for (to_test) |users_count| {
{
const null_term_query_str = try std.fmt.bufPrintZ(&line_buffer, "DELETE User {{}}", .{});
var toker = ziqlTokenizer.init(null_term_query_str);
var parser = ziqlParser.init(&toker, &db_engine.file_engine, &db_engine.schema_engine);
try parser.parse();
}
// Populate with random dummy value
// Need some speed up, spended times to find that it is the parsonConditionValue that take time, the last switch to be exact, that parse str to value
{
@ -68,7 +75,7 @@ pub fn main() !void {
for (users_count - 1) |_| {
try writer.print(
"('{s}', '{s}', {d}, [ {d} ], none, none, {s}, {s}, {s})",
"('{s}', '{s}', {d}, [ {d} ], {{}}, none, {s}, {s}, {s})",
.{
names[rng.uintAtMost(usize, names.len - 1)],
emails[rng.uintAtMost(usize, emails.len - 1)],
@ -100,6 +107,16 @@ pub fn main() !void {
std.debug.print("--------------------------------------\n\n", .{});
}
{
for (db_engine.schema_engine.struct_array) |sstruct| {
const mb: f64 = @as(f64, @floatFromInt(sstruct.uuid_file_index.arena.queryCapacity())) / 1024.0 / 1024.0;
std.debug.print("Sstruct: {s}\n", .{sstruct.name});
std.debug.print("Memory: {d:.2}Mb\n", .{mb});
std.debug.print("Count: {d}\n\n", .{sstruct.uuid_file_index.map.count()});
std.debug.print("--------------------------------------\n\n", .{});
}
}
// Define your benchmark queries
{
const queries = [_][]const u8{
@ -109,7 +126,8 @@ pub fn main() !void {
"GRAB User {name = 'Charlie'}",
"GRAB User {age > 30}",
"GRAB User {bday > 2000/01/01}",
"DELETE User {}",
"GRAB User {age > 30 AND name = 'Charlie' AND bday > 2000/01/01}",
"GRAB User {best_friend IN {name = 'Charlie'}}",
};
// Run benchmarks
@ -123,12 +141,23 @@ pub fn main() !void {
try parser.parse();
const end_time = std.time.nanoTimestamp();
const duration = @as(f64, @floatFromInt(end_time - start_time)) / 1e9;
const duration = @as(f64, @floatFromInt(end_time - start_time)) / 1e6;
std.debug.print("Query: \t\t{s}\nDuration: \t{d:.6} seconds\n\n", .{ query, duration });
std.debug.print("Query: \t\t{s}\nDuration: \t{d:.6} ms\n\n", .{ query, duration });
}
std.debug.print("=====================================\n\n", .{});
}
{
for (db_engine.schema_engine.struct_array) |sstruct| {
const mb: f64 = @as(f64, @floatFromInt(sstruct.uuid_file_index.arena.queryCapacity())) / 1024.0 / 1024.0;
std.debug.print("Sstruct: {s}\n", .{sstruct.name});
std.debug.print("Memory: {d:.2}Mb\n", .{mb});
std.debug.print("Count: {d}\n\n", .{sstruct.uuid_file_index.map.count()});
std.debug.print("--------------------------------------\n\n", .{});
}
}
}
}
}

View File

@ -4,7 +4,7 @@ pub fn build(b: *std.Build) void {
// Exe
// -----------------------------------------------
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{ .preferred_optimize_mode = .ReleaseFast });
const optimize = b.standardOptimizeOption(.{ .preferred_optimize_mode = .ReleaseSafe });
const exe = b.addExecutable(.{
.name = "ZipponDB",

View File

@ -134,13 +134,27 @@ test "DELETE" {
try testParsing(db, "DELETE User {}");
}
test "3 struct ADD" {
test "3 struct base" {
const db = DB{ .path = "test2", .schema = "schema/3struct" };
try testParsing(db, "DELETE User {}");
try testParsing(db, "DELETE Post {}");
try testParsing(db, "ADD User (name = 'Bob', email='bob@email.com', age=55, friends=none, posts=none, comments=none, bday=2000/01/01)");
try testParsing(db, "ADD Post (text = 'Hello every body', at=NOW, from={}, comments=none)");
try testParsing(db, "ADD Post (text = 'Hello every body', at=NOW, from={}, comments=none)");
try testParsing(db, "GRAB Post [id, text, at, from [id, name]] {}");
}
test "3 struct both side" {
const db = DB{ .path = "test2", .schema = "schema/3struct" };
try testParsing(db, "DELETE User {}");
try testParsing(db, "DELETE Post {}");
try testParsing(db, "ADD User (name = 'Bob', email='bob@email.com', age=55, friends=none, posts=none, comments=none, bday=2000/01/01)");
try testParsing(db, "ADD Post (text = 'Hello every body', at=NOW, from=none, comments=none)");
try testParsing(db, "ADD Post (text = 'Hello every body', at=NOW, from={}, comments=none)");
try testParsing(db, "ADD Post (text = 'Hello every body', at=NOW, from={}, comments=none) -> new_post -> UPDATE User {} TO (posts APPEND new_post)");
// try testParsing(db, "ADD Post (text = 'Hello every body', at=NOW, from={} APPEND TO posts, comments=none)"); Maybe I can use that to be like the above query
// ADD Post (text = 'Hello every body', at=NOW, from={} TO last_post, comments=none) And this for a single link
// try testParsing(db, "ADD Post (text = 'Hello every body', at=NOW, from={} APPEND TO [posts, last_post], comments=none)"); Can be an array to add it to multiple list
// last_post is replaced instead of append
try testParsing(db, "GRAB Post [id, text, at, from [id, name]] {}");
try testParsing(db, "GRAB User [id, name] {}");
}