nodesource / nodejs-package-benchmark

Node.js benchmark for common web developer workloads. Inspired by https://github.com/v8/web-tooling-benchmark
29 stars 1 forks source link

Add typescript benchmark #19

Closed arthurfiorette closed 4 months ago

arthurfiorette commented 4 months ago

closes #15

This PR adds 3 typescript benchmarks.

Output sample:

Running Node.js Package Benchmark...
---------------------------------------------------------------
typescript
  transpile:                                                   79.51 (10 samples)
  createSourceFile:                                            1.914K (192 samples)
  getTypeChecker:                                              4.345 (10 samples)
---------------------------------------------------------------
arthurfiorette commented 4 months ago

If I undestood correctly:

Baseline:

./bench-it.js $(which node) baseline

7e25625544dc7437012c5d5afa08e282b53cefd2
Running Node.js Package Benchmark...
--------------------------------------------
typescript
  transpile:                                85.48 (10 samples)
  createSourceFile:                         2.715K (272 samples)
  getSemanticDiagnostics:                   3.241 (10 samples)

did this changes:

diff --git a/src/typescript-benchmark.js b/src/typescript-benchmark.js
index cb7095a..85d06e5 100644
--- a/src/typescript-benchmark.js
+++ b/src/typescript-benchmark.js
@@ -1,6 +1,7 @@
 const fs = require("node:fs");
 const ts = require("typescript");
 const path = require("node:path");
+const assert = require("node:assert");

 const filePath = path.join(__dirname, "..", "fixtures", "ts-sample.ts");
 const code = fs.readFileSync(filePath, "utf8");
@@ -12,7 +13,7 @@ module.exports = {
                {
                        name: "transpile",
                        fn: () => {
-                               ts.transpile(
+                               const transpiled = ts.transpile(
                                        code,
                                        {
                                                // CJS Settings
@@ -32,18 +33,22 @@ module.exports = {
                                        },
                                        filePath,
                                );
+
+        assert.ok(transpiled)
                        },
                },
                {
                        name: "createSourceFile",
                        fn: () => {
-                               ts.createSourceFile(
+                               const source = ts.createSourceFile(
                                        filePath,
                                        code,
                                        ts.ScriptTarget.ESNext,
                                        false,
                                        ts.ScriptKind.TS,
                                );
+
+        assert.ok(source)
                        },
                },
                {
@@ -74,7 +79,9 @@ module.exports = {
                                        },
                                });

-                               program.getSemanticDiagnostics(program.getSourceFile(filePath));
+                               const diagnostics = program.getSemanticDiagnostics(program.getSourceFile(filePath));
+
+        assert.ok(diagnostics.length === 0);
                        },
                },
        ],
./bench-it.js $(which node)

Running Node.js Package Benchmark...
--------------------------------------------
typescript
  transpile:                                76.11 (10 samples)
  createSourceFile:                         2.61K (261 samples)
  getSemanticDiagnostics:                   3.102 (10 samples)

I don't think dead code elimination is in place... Should be that way, right?

arthurfiorette commented 4 months ago

I've also added another commit improving how the output is printed in TTY mode. Previously it collected all results and then printed it out, now it whenever a new result comes, it gets printed out.

It helps by giving feedback on what run it is currently, how many were already finished and how many are waiting to be ran.

Also added machine info in TTY mode, which gives some basic informations when mentally comparing results across machines/node versions.

However feel free to revert it if you don't like the result.

RafaelGSS commented 4 months ago

Thanks!