~ knotless Search/
↑↓ move↵ open⇧↵ all results

zat.dev/zds

atproto pds · mirror of https://tangled.org/zat.dev/zds

0
0
19 lines · 1.0 KB Raw History
const std = @import("std");
const scopes = @import("scopes");

pub fn main() void {
    const grants = "space:fm.plyr.privateMedia?authority=did:plc:alice&skey=self&collection=fm.plyr.track&action=read&action=create&manage=update";
    const iterations = 1_000_000;
    const start = std.Io.Clock.awake.now(std.Options.debug_io).toNanoseconds();
    var allowed: usize = 0;
    for (0..iterations) |i| {
        const action: scopes.SpaceAction = if (i % 2 == 0) .read_self else .create;
        const collection: ?[]const u8 = if (i % 2 == 0) null else "app.other.thing";
        std.mem.doNotOptimizeAway(action);
        const result = scopes.spaceAllows(grants, action, "fm.plyr.privateMedia", "did:plc:alice", "self", collection);
        std.mem.doNotOptimizeAway(result);
        allowed += @intFromBool(result);
    }
    const elapsed = std.Io.Clock.awake.now(std.Options.debug_io).toNanoseconds() - start;
    std.debug.print("space scopes: {d} operations, {d} allowed, {d} ns/op\n", .{ iterations, allowed, @divTrunc(elapsed, iterations) });
}