gitoria

calendar

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmainf9b8f918Merge branch 'calendar-vendor-day61' into mainAtlasmain/plugins/mpackdb/bench_open.zig

4.0 KB

  1. // Mission 436 bench: open/close timing and index dump of an mpackdb store.
  2. // bench_open gen <dbfile> <n> write a synthetic store (pk '@id' 24-hex, '!oldId' 24-hex), no index files
  3. // bench_open open <dbfile> time open + close (schema @id, !oldId, compact=false)
  4. // bench_open dump <dbfile> <out> open and write every index entry (field,key,off,len) to <out>
  5. const std = @import("std");
  6. const msgpack = @import("msgpack.zig");
  7. const engine = @import("engine.zig");
  8. const linux = std.os.linux;
  9. fn nowNs() i128 {
  10. var ts: linux.timespec = undefined;
  11. _ = linux.clock_gettime(linux.CLOCK.MONOTONIC, &ts);
  12. return @as(i128, ts.sec) * 1_000_000_000 + ts.nsec;
  13. }
  14. pub fn main(init: std.process.Init) !void {
  15. const gpa = init.gpa;
  16. var iter = std.process.Args.Iterator.init(init.minimal.args);
  17. _ = iter.next();
  18. const cmd = iter.next() orelse return;
  19. const dbfile = iter.next() orelse return;
  20. if (std.mem.eql(u8, cmd, "gen")) {
  21. const n = try std.fmt.parseInt(usize, iter.next().?, 10);
  22. var base: []const u8 = dbfile;
  23. if (std.mem.endsWith(u8, base, ".db")) base = base[0 .. base.len - 3];
  24. const path = try std.fmt.allocPrintSentinel(gpa, "{s}.mpack", .{base}, 0);
  25. const fd: i32 = @bitCast(@as(u32, @truncate(linux.open(path, .{ .ACCMODE = .WRONLY, .CREAT = true, .TRUNC = true }, 0o644))));
  26. var out: std.ArrayList(u8) = .empty;
  27. var prng = std.Random.DefaultPrng.init(42);
  28. const r = prng.random();
  29. var arena_state = std.heap.ArenaAllocator.init(gpa);
  30. var i: usize = 0;
  31. while (i < n) : (i += 1) {
  32. _ = arena_state.reset(.retain_capacity);
  33. const a = arena_state.allocator();
  34. const id = try std.fmt.allocPrint(a, "{x:0>16}", .{r.int(u64)});
  35. const old = try std.fmt.allocPrint(a, "60f2{x:0>8}{x:0>12}", .{ r.int(u32), i });
  36. const entries = try a.alloc(msgpack.Entry, 4);
  37. entries[0] = .{ .key = .{ .str = "id" }, .value = .{ .str = id } };
  38. entries[1] = .{ .key = .{ .str = "oldId" }, .value = .{ .str = old } };
  39. entries[2] = .{ .key = .{ .str = "name" }, .value = .{ .str = "Some Person Name" } };
  40. entries[3] = .{ .key = .{ .str = "n" }, .value = .{ .number = @floatFromInt(i) } };
  41. const framed = try msgpack.serialize(a, .{ .map = entries });
  42. try out.appendSlice(gpa, framed);
  43. if (out.items.len > 1 << 20) {
  44. _ = linux.write(fd, out.items.ptr, out.items.len);
  45. out.clearRetainingCapacity();
  46. }
  47. }
  48. _ = linux.write(fd, out.items.ptr, out.items.len);
  49. _ = linux.close(fd);
  50. return;
  51. }
  52. const t0 = nowNs();
  53. const db = try engine.Db.open(gpa, dbfile, .{ .primary_key = "@id", .indexes = &.{"!oldId"}, .compact = false });
  54. const t1 = nowNs();
  55. if (std.mem.eql(u8, cmd, "dump")) {
  56. const outp = try std.fmt.allocPrintSentinel(gpa, "{s}", .{iter.next().?}, 0);
  57. var buf: std.ArrayList(u8) = .empty;
  58. var it = db.idx.iterator();
  59. while (it.next()) |kv| {
  60. for (kv.value_ptr.entries.items) |e| {
  61. var kb: [40]u8 = undefined;
  62. const ks = switch (e.key) {
  63. .num => |x| engine.jsNumFmt(&kb, x),
  64. .str => |s| s,
  65. };
  66. const line = try std.fmt.allocPrint(gpa, "{s}\t{s}\t{d}\t{d}\n", .{ kv.key_ptr.*, ks, e.off, e.len });
  67. defer gpa.free(line);
  68. try buf.appendSlice(gpa, line);
  69. }
  70. }
  71. const fd: i32 = @bitCast(@as(u32, @truncate(linux.open(outp, .{ .ACCMODE = .WRONLY, .CREAT = true, .TRUNC = true }, 0o644))));
  72. var off: usize = 0;
  73. while (off < buf.items.len) {
  74. const rc = linux.write(fd, buf.items.ptr + off, buf.items.len - off);
  75. off += rc;
  76. }
  77. _ = linux.close(fd);
  78. }
  79. const t2 = nowNs();
  80. db.close();
  81. const t3 = nowNs();
  82. std.debug.print("open {d} ms, close {d} ms\n", .{ @divTrunc(t1 - t0, 1_000_000), @divTrunc(t3 - t2, 1_000_000) });
  83. }

Branches

Latest commits

  • f9b8f918Merge branch 'calendar-vendor-day61' into mainAtlas
  • 66341793|||PR Vendor Hybriel day61Atlas
  • 36fc596bMerge branch 'vendor-day59' into mainAtlas
  • b37cc1da|||PR Vendor Hybriel day59Atlas
  • 05665102Merge branch 'vendor-day56' into mainAtlas
  • 687296fb|||PR Vendor Hybriel day56Atlas
  • a6166d4eMerge branch 'hl-standard-3' into mainAtlas
  • 6d0eb3b0|||PR Calendar day add buttons only when signed in (Kunibert minor)Atlas
  • add4b499|||PR Make calendar day actions keyboard accessibleAtlas
  • 79e49b4dMerge branch 'hl-standard' into mainAtlas
  • e9fec7bb|||PR HL-STANDARD clean-up: typed parameters, plain locals, by-reference cacheAtlas
  • eff166a4Re-vendor complete Hybriel plugins and runtime to day44mre
  • cef81394Wait for the DST fixture page instead of an unused socketmre
  • 42434f47Check lazy-session cookies after login with a stored anonymous fixturemre
  • 728e84e3Re-vendor complete Hybriel day41 plugin directoriesmre
  • cbd7ff43Backup tar: --hard-dereference, so mpackdb sidecars are never stored as hard links (Tracker's finding)mre
  • 59d1da0acalendar: plain declarations instead of needless let in 9 files (calendar#17): 49 declarations that are never reassigned; reassigned ones and the timer closure's p stay letmre
  • f5415cf9calendar: the Style blocks in the language's nested form (calendar#16): rules named after the View's own elements with their children nested, pseudo-classes and @media nested, merged duplicate select rule; same CSS, shots identical in Chrome at 4 sizesmre
  • edb7c947calendar: the sign-in callback keeps the session it finds and signs it in (same cookie, nothing signed out; ident#28); security gate 56+4 failing → 60 passedmre
  • bf8cc0fcStyles move into their components: the shell's styles into main.hl, the events and the editors into the month view's Style block; styles.hl keeps only the theme inherit, the accent and the message line; .gitignore ignores a bin symlink too; tests/styles-shots.mjs for the before/after pixel comparemre