This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |