diff options
| author | Gabriel Schneider <[email protected]> | 2026-08-02 17:38:06 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-08-02 23:11:01 -0300 |
| commit | a9263daee9413c5eff3c1f1bebcd224442fd8685 (patch) | |
| tree | f0a74fe1420cd9933cb2f85dc8313914aa674e94 /vrsite/bench_test.go | |
| parent | e16f78b255bcf46d8c6f9a4b9e76dd7a3817edeb (diff) | |
| download | notevi-a9263daee9413c5eff3c1f1bebcd224442fd8685.tar.gz notevi-a9263daee9413c5eff3c1f1bebcd224442fd8685.zip | |
vrsite: toggle repository file list
Diffstat (limited to 'vrsite/bench_test.go')
| -rw-r--r-- | vrsite/bench_test.go | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/vrsite/bench_test.go b/vrsite/bench_test.go index 6e3f907..babf3d4 100644 --- a/vrsite/bench_test.go +++ b/vrsite/bench_test.go @@ -58,7 +58,8 @@ static GREETING: &str = "hello \"quoted\" <world> & friends"; // One chunk per language whose query leans on a predicate, to keep an eye on // what predicates cost: go's builtin list is an #any-of? (a byte compare per // call), while python, javascript and C run a casing regex over every -// identifier they see. +// identifier they see — and zig, which names its types by casing alone, runs +// two. var langChunks = []struct { path string src []byte @@ -200,6 +201,40 @@ int entry_lookup(struct cache_entry *e, const char *key) { return e->key != NULL && strcmp(e->key, key) == 0; } `)}, + {"bench.zig", []byte(`// Cache entries with hit counts. +const std = @import("std"); + +const MAX_ENTRIES: usize = 4096; + +const CacheEntry = struct { + key: []const u8, + value: []u8, + hits: u64 = 0, + + fn init(key: []const u8, value: []u8) CacheEntry { + return CacheEntry{ .key = key, .value = value }; + } + + fn stale(self: CacheEntry) bool { + return self.hits > MAX_ENTRIES; + } + + fn touch(self: *CacheEntry) u64 { + self.hits += 1; + if (self.hits % 100 == 0) { + std.debug.print("entry {s} hit {d} times \"escaped\"\n", .{ self.key, self.hits }); + } + return self.hits; + } + + fn lookup(self: CacheEntry, keys: []const []const u8) ?[]u8 { + for (keys) |k| { + if (std.mem.eql(u8, k, self.key)) return self.value; + } + return null; + } +}; +`)}, } func synth(chunk []byte, size int) []byte { |
