This is a comparison of two functions that sum up all the integer numbers from 1 to n
and returns that sum.
$ deno test --allow-read add.ts
Check file:///home/wperron/github.com/wperron/gists/add/add.ts
running 4 benchmarks ...
#!/usr/bin/env -S deno run --allow-net --allow-read | |
(() => { | |
var __defProp = Object.defineProperty; | |
var __export = (target2, all) => { | |
for (var name in all) | |
__defProp(target2, name, {get: all[name], enumerable: true}); | |
}; | |
// _util/os.ts | |
var osType = (() => { |
fruit | qty | |
---|---|---|
apple | 1 | |
banana | 2 | |
cantaloupe | 3 |
import { assertEquals } from "./testing/asserts.ts"; | |
Deno.test("a", () => { | |
assertEquals("lorem ipsum something foobar baz", "lorem ipsum some other thing foobar baz"); | |
}); | |
Deno.test("aa", () => { | |
assertEquals("this is different from the other string", "lorem ipsum some other thing foobar baz"); | |
}); |
import { delay } from "https://deno.land/[email protected]/async/delay.ts"; | |
const send = new BroadcastChannel("a"); | |
const recv = new BroadcastChannel("a"); | |
addEventListener("fetch", (event) => { | |
event.respondWith(handler(event.request)); | |
}) | |
function handler(_req) { |
addEventListener("fetch", (event) => { | |
event.respondWith(handler(event.request)); | |
}); | |
async function handler(req: Request): Promise<Response> { | |
if (typeof BroadcastChannel !== "undefined") { | |
console.log("found broadcast channel"); | |
return new Response("true"); | |
} | |
return new Response("false"); |
// includes-all | |
needles.map((elem) => haystack.includes(elem)).reduce((found, curr) => found && curr); | |
// includesAny | |
needles.some((elem) => haystack.includes(elem)); | |
// includesNone | |
!needles.some((elem) => haystack.includes(elem)); | |
// mapNotNullish |
addEventListener("fetch", (e) => { | |
let ray = e.request.headers.get("x-deno-ray"); | |
console.log(ray); | |
e.respondWith(new Response(ray, {status: 200})); | |
}); |
addEventListener("fetch", (e) => { | |
e.respondWith(handler(e)); | |
}); | |
function handler(e) { | |
return fetch(e.request) | |
} |
import { cyan } from "https://deno.land/[email protected]/fmt/colors.ts"; | |
export function fib(n: number): number { | |
if (0 <= n && n <= 1) { | |
return n; | |
} | |
let a = 0, b = 1; | |
for (let i = 0; i < n; i++) { | |
[a, b] = [b, a + b]; |