Deno Vs Node performance comparison: Writing files

Mayank C
Tech Tonic

--

This article is a continuation of Deno Vs Node performance series. In earlier articles, we’ve seen the comparison for:

In this article, we’ll see the performance comparison in writing text files.

Test

The test simply writes a given string into a file (overrides by default). The test is repeated 10K times for different file sizes. The Deno and Node.js code is as follows:

Deno code

No imports are required, as the writeTextFile API is part of the core runtime.

async function test(runs: Number, data: string) {
for (let i = 0; i < runs; i++) {
await Deno.writeTextFile("./testdata/output.txt", data);
}
}

Node code

An import of the writeFile API from core fs module is required.

const { writeFile } = require("fs").promises;async function test(runs, data) {
for (let i = 0; i < runs; i++) {
await writeFile("./testdata/output.txt", data);
}
}

Test data

A test run consists of writing to a given file 10K times. There are four test data with different sizes (1K, 10K, 500K, and 2M). The source data is prepared by reading a file at startup:

$ ls -l 1K.txt
-rw-r--r--@ 1 mayankc staff 1095 Mar 19 17:38 1K.txt
$ ls -l 10K.txt
-rw-r--r--@ 1 mayankc staff 9510 Mar 19 11:41 10K.txt
$ ls -l 500K.txt
-rw-r--r--@ 1 mayankc staff 511274 Mar 19 11:35 500K.txt
$ ls -l 2M.txt
-rw-r--r-- 1 mayankc staff 1922394 Feb 12 11:26 2M.txt

Versions

The Deno and Node.js versions are as follows:

$ deno -V
deno 1.20.1
$ node -v
v17.7.2

Both are latest at the time of writing (19th March 2022).

Test results

The test results for each file size are as follows:

1K data

Deno’s performance is comparable to Node.js

10K data

Deno’s performance is comparable to Node.js

500K data

Deno’s performance is slightly slower than Node.js

2M data

Deno’s performance is slightly faster than Node.js

Conclusion

Overall, Deno’s performance is comparable with Node.js for all file sizes.

--

--