Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

chore: add gzip size in comparison #78

Merged
merged 3 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 14 additions & 20 deletions benchmark/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { parse, stringify, uneval } from "devalue";
import c from "kleur";
import * as superjson from "superjson";
import { createTson, tsonDate, tsonRegExp, tsonSet } from "tupleson";
import { gzipSync } from "zlib";

const obj = {
array: [{ foo: 1 }, { bar: 2 }, { baz: 3 }],
Expand All @@ -19,6 +20,7 @@ const obj = {
// obj.self = obj;

const tson = createTson({
nonce: () => "__",
types: [tsonDate, tsonRegExp, tsonSet],
});

Expand All @@ -28,27 +30,19 @@ const devalue_stringified = stringify(obj);
const arson_stringified = ARSON.stringify(obj);
const tson_serialized = tson.stringify(obj);

console.log(
`superjson output: ${c.bold().cyan(superjson_serialized.length)} bytes`,
);

console.log(`tson output: ${c.bold().cyan(tson_serialized.length)} bytes`);
// console.log(superjson_serialized);
console.log(
`devalue.uneval output: ${c.bold().cyan(devalue_unevaled.length)} bytes`,
);
// console.log(devalue_unevaled);
console.log(
`devalue.stringify output: ${c
.bold()
.cyan(devalue_stringified.length)} bytes`,
);
// console.log(devalue_stringified);
console.log(`arson output: ${c.bold().cyan(arson_stringified.length)} bytes`);
// console.log(arson_stringified);
const printSize = (label, str) => {
console.log(
`${label}: ${c.bold().cyan(str.length)} bytes / ${c
.bold()
.cyan(gzipSync(str).length)} bytes gzipped`,
);
};

// const superjson_deserialized = superjson.parse(superjson_serialized);
// const devalue_deserialized = eval(`(${devalue_unevaled})`);
printSize("superjson", superjson_serialized);
printSize("tson", tson_serialized);
printSize("devalue.uneval", devalue_unevaled);
printSize("devalue.stringify", devalue_stringified);
printSize("arson", arson_stringified);

const iterations = 1e6;

Expand Down
5 changes: 3 additions & 2 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
"pnpm-lock.yaml"
],
"words": [
"clsx",
"Codecov",
"codespace",
"commitlint",
"contributorsrc",
"conventionalcommits",
"deferreds",
"gzipped",
"Iterarable",
"KATT",
"kleur",
Expand All @@ -32,7 +34,6 @@
"tsup",
"tupleson",
"unevaled",
"wontfix",
"clsx"
"wontfix"
]
}
Loading