Skip to content

Instantly share code, notes, and snippets.

// Dependencies: ts-pattern, mitata
import { match, P } from 'ts-pattern';
import { summary, run, bench, type k_state, do_not_optimize } from 'mitata';
summary(() => {
type Data =
| { type: 'text'; content: string }
| { type: 'img'; src: string };
// Dependencies: timsort2, mitata
import { bench, do_not_optimize, run, summary, type k_state } from "mitata";
import { sort } from "timsort2";
const tests = [
function randomInt(n: number): number[] {
const arr: number[] = new Array(n);
for (let i = 0; i < n; i++) {
arr[i] = (Math.random() * 9007199254740992) | 0;
import * as st from 'safe-throw';
import * as retry from 'safe-throw/retry';
const fetchDomainByNameForUser = retry.untilAsync(
(res) => !st.isErr(res),
async (domainName: string, userId: string) => {
const authResult = await native.tryPromise(
Auth.check({
action: 'query',
resource: 'domains',
@aquapi
aquapi / lexer.zig
Created November 19, 2024 17:49
Basic lexer
const std = @import("std");
const mem = std.mem;
pub const Token = struct {
pub const ArrayList = std.ArrayList(Token);
const StringMap = std.StaticStringMap(Kind);
pub const keywordsMap = StringMap.initComptime(.{
// Conditions
.{ "if", Kind.keywordIf },
// This is a proof of concept implementation since
// Mapl doesn't have built-in signer yet
import { jitc, router, staticException } from '@mapl/app';
import jwt from 'jsonwebtoken';
import Signer from '@bit-js/ncrypt/basic-signer';
import ValueSigner from '@bit-js/ncrypt/value-signer';
const SECRET = 'linux';
import { group, run, bench } from 'mitata';
// Do warmup
for (let i = 0; i < 10; i++) bench('noop', () => { });
group('Set vs array vs literal', () => {
// Do checks with arrays
const arr = ['hi', 'there', 'nagna', 'randomlongstring', 'small'];
const arrInclude = (item) => arr.includes(item);
@aquapi
aquapi / compact.txt
Last active November 20, 2023 16:11
Benchmark results
Stric x 45827 req/sec
Vix x 45412 req/sec
Elysia x 44004 req/sec
Hono x 42643 req/sec
Bunicorn x 39660 req/sec
Fastest is Stric.
@aquapi
aquapi / stric.ts
Last active August 10, 2023 19:17
Stric example code
import { Router, macro } from '@stricjs/router';
import { qs } from '@stricjs/utils';
// Create a query parser that only search for key `name` in the query
const parse = qs.searchKey('name');
export default new Router({ base: 'http://localhost:3000' })
// Return 'Hi' on every requests to '/'
.get('/', macro('Hi'))
// Yield back the JSON that the request sent