summaryrefslogtreecommitdiff
path: root/cli/bench/fs/serve.jsx
blob: 51125235fe8bcb06e06ed3fee44479b42c7bb595 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

/** @jsx h */
import results from "./deno.json" assert { type: "json" };
import nodeResults from "./node.json" assert { type: "json" };
import { h, ssr } from "https://crux.land/nanossr@0.0.4";
import { router } from "https://crux.land/router@0.0.11";

function once(fn) {
  let called = false;
  let result;
  return function () {
    if (!called) {
      called = true;
      result = fn();
      return result;
    }
    return result;
  };
}

const body = once(() =>
  Object.entries(results).map(([name, data]) => (
    <tr>
      <td class="border px-4 py-2">{name}</td>
      <td class="border px-4 py-2">
        {data.reduce((a, b) => a + b, 0) / data.length} ops/sec
      </td>
      <td class="border px-4 py-2">
        {nodeResults[name].reduce((a, b) => a + b, 0) /
          nodeResults[name].length} ops/sec
      </td>
    </tr>
  ))
);

function App() {
  return (
    <table class="table-auto">
      <thead>
        <tr>
          <th class="px-4 py-2">Benchmark</th>
          <th class="px-4 py-2">Deno</th>
          <th class="px-4 py-2">Node</th>
        </tr>
      </thead>
      <tbody>
        {body()}
      </tbody>
    </table>
  );
}

const { serve } = Deno;
serve(router({
  "/": () => ssr(() => <App />),
}));