Skip to content

Commit

Permalink
Performance improvements 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
JairusSW committed May 14, 2021
1 parent 6f58818 commit db77a73
Show file tree
Hide file tree
Showing 14 changed files with 310 additions and 104 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ const deserialized = kati.parse(serialized)
console.log('Deserialized: ' + deserialized)
```

## Going faster

You can serialize types seperately by using `stringify.from(Array/Object/String/Number/Null/Boolean)`

```js
const kati = require('kati')

// fromObject is faster
const serialized = kati.stringify.fromObject({
hello: 'world',
array: ['Hey!', 3.14]
})

console.log('Serialized: ' + stringified)

const deserialized = kati.parse(serialized)

console.log('Deserialized: ' + deserialized)
```

## Benchmarks

**Serialize Array**
Expand Down
14 changes: 6 additions & 8 deletions bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ const examples = {
string: 'HelloWorldFireTruck',
number: 134567890.098764321,
array: ['HelloWorldFireTruck', 0],
object: {
'0': 'HelloWorldFireTruck'
}
object: { 0: 'HelloWorldFireTruck' }
}

// NOTE: Tiny things, because its geared for small data packets in things such as WebSockets or Networking.
b.suite(
'Kati vs. JSON (Array)',

b.add('Kati Serialize', () => {
Kati.stringify(examples.array)
Kati.stringify.fromArray(examples.array)
}),

b.add('JSON Serialize', () => {
Expand Down Expand Up @@ -50,7 +48,7 @@ b.suite(
'Kati vs. JSON (Object)',

b.add('Kati Serialize', () => {
Kati.stringify(examples.object)
Kati.stringify.fromObject(examples.object)
}),

b.add('JSON Serialize', () => {
Expand Down Expand Up @@ -79,7 +77,7 @@ b.suite(
'Kati vs. JSON (String)',

b.add('Kati Serialize', () => {
Kati.stringify(examples.string)
Kati.stringify.fromString(examples.string)
}),

b.add('JSON Serialize', () => {
Expand Down Expand Up @@ -108,7 +106,7 @@ b.suite(
'Kati vs. JSON (Number)',

b.add('Kati Serialize', () => {
Kati.stringify(examples.number)
Kati.stringify.fromNumber(examples.number)
}),

b.add('JSON Serialize', () => {
Expand Down
10 changes: 5 additions & 5 deletions benchmark/results/array.chart.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</head>
<body>
<div style="max-width: 800px">
<canvas id="chart1620916250885" width="16" height="9"></canvas>
<canvas id="chart1621006698640" width="16" height="9"></canvas>
</div>
<script>
const format = (num) => {
Expand All @@ -34,10 +34,10 @@

return chunked.map((chunk) => chunk.join("")).join(" ");
};
const ctx1620916250885 = document
.getElementById("chart1620916250885")
const ctx1621006698640 = document
.getElementById("chart1621006698640")
.getContext("2d");
const chart1620916250885 = new Chart(ctx1620916250885, {
const chart1621006698640 = new Chart(ctx1621006698640, {
type: "bar",
data: {
labels: [
Expand All @@ -49,7 +49,7 @@
],
datasets: [
{
data: [10270546, 3275949, 487794, 690993, 113275],
data: [17993392, 2974374, 477426, 670959, 109990],
backgroundColor: [
"rgba(63, 142, 252, 0.8)",
"rgba(116, 165, 127, 0.8)",
Expand Down
30 changes: 15 additions & 15 deletions benchmark/results/array.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
{
"name": "Kati vs. JSON (Array)",
"date": "2021-05-13T14:30:50.885Z",
"date": "2021-05-14T15:38:18.640Z",
"version": "1.0.0",
"results": [
{
"name": "Kati Serialize",
"ops": 10270546,
"margin": 3.6,
"ops": 17993392,
"margin": 0.88,
"percentSlower": 0
},
{
"name": "JSON Serialize",
"ops": 3275949,
"margin": 1.09,
"percentSlower": 68.1
"ops": 2974374,
"margin": 4.51,
"percentSlower": 83.47
},
{
"name": "Flatted Serialize",
"ops": 487794,
"margin": 1.75,
"percentSlower": 95.25
"ops": 477426,
"margin": 2.61,
"percentSlower": 97.35
},
{
"name": "JSON5 Serialize",
"ops": 690993,
"margin": 0.64,
"percentSlower": 93.27
"ops": 670959,
"margin": 1.34,
"percentSlower": 96.27
},
{
"name": "YAML Serialize",
"ops": 113275,
"margin": 7.22,
"percentSlower": 98.9
"ops": 109990,
"margin": 2.38,
"percentSlower": 99.39
}
],
"fastest": {
Expand Down
10 changes: 5 additions & 5 deletions benchmark/results/number.chart.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</head>
<body>
<div style="max-width: 800px">
<canvas id="chart1620916332720" width="16" height="9"></canvas>
<canvas id="chart1621006781901" width="16" height="9"></canvas>
</div>
<script>
const format = (num) => {
Expand All @@ -34,10 +34,10 @@

return chunked.map((chunk) => chunk.join("")).join(" ");
};
const ctx1620916332720 = document
.getElementById("chart1620916332720")
const ctx1621006781901 = document
.getElementById("chart1621006781901")
.getContext("2d");
const chart1620916332720 = new Chart(ctx1620916332720, {
const chart1621006781901 = new Chart(ctx1621006781901, {
type: "bar",
data: {
labels: [
Expand All @@ -49,7 +49,7 @@
],
datasets: [
{
data: [816728460, 3182708, 898440, 7304907, 293328],
data: [853425009, 3587464, 1023898, 7914178, 292563],
backgroundColor: [
"rgba(63, 142, 252, 0.8)",
"rgba(116, 165, 127, 0.8)",
Expand Down
30 changes: 15 additions & 15 deletions benchmark/results/number.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
{
"name": "Kati vs. JSON (Number)",
"date": "2021-05-13T14:32:12.720Z",
"date": "2021-05-14T15:39:41.901Z",
"version": "1.0.0",
"results": [
{
"name": "Kati Serialize",
"ops": 816728460,
"margin": 0.67,
"ops": 853425009,
"margin": 0.82,
"percentSlower": 0
},
{
"name": "JSON Serialize",
"ops": 3182708,
"margin": 9.9,
"percentSlower": 99.61
"ops": 3587464,
"margin": 3.75,
"percentSlower": 99.58
},
{
"name": "Flatted Serialize",
"ops": 898440,
"margin": 4.34,
"percentSlower": 99.89
"ops": 1023898,
"margin": 2.42,
"percentSlower": 99.88
},
{
"name": "JSON5 Serialize",
"ops": 7304907,
"margin": 3.48,
"percentSlower": 99.11
"ops": 7914178,
"margin": 6.17,
"percentSlower": 99.07
},
{
"name": "YAML Serialize",
"ops": 293328,
"margin": 3.23,
"percentSlower": 99.96
"ops": 292563,
"margin": 4.13,
"percentSlower": 99.97
}
],
"fastest": {
Expand Down
10 changes: 5 additions & 5 deletions benchmark/results/object.chart.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</head>
<body>
<div style="max-width: 800px">
<canvas id="chart1620916278234" width="16" height="9"></canvas>
<canvas id="chart1621006726357" width="16" height="9"></canvas>
</div>
<script>
const format = (num) => {
Expand All @@ -34,10 +34,10 @@

return chunked.map((chunk) => chunk.join("")).join(" ");
};
const ctx1620916278234 = document
.getElementById("chart1620916278234")
const ctx1621006726357 = document
.getElementById("chart1621006726357")
.getContext("2d");
const chart1620916278234 = new Chart(ctx1620916278234, {
const chart1621006726357 = new Chart(ctx1621006726357, {
type: "bar",
data: {
labels: [
Expand All @@ -49,7 +49,7 @@
],
datasets: [
{
data: [3590481, 1977988, 460301, 513727, 88548],
data: [3231742, 1583180, 288369, 352397, 62474],
backgroundColor: [
"rgba(63, 142, 252, 0.8)",
"rgba(116, 165, 127, 0.8)",
Expand Down
30 changes: 15 additions & 15 deletions benchmark/results/object.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
{
"name": "Kati vs. JSON (Object)",
"date": "2021-05-13T14:31:18.234Z",
"date": "2021-05-14T15:38:46.357Z",
"version": "1.0.0",
"results": [
{
"name": "Kati Serialize",
"ops": 3590481,
"margin": 2.05,
"ops": 3231742,
"margin": 6.27,
"percentSlower": 0
},
{
"name": "JSON Serialize",
"ops": 1977988,
"margin": 0.86,
"percentSlower": 44.91
"ops": 1583180,
"margin": 12.15,
"percentSlower": 51.01
},
{
"name": "Flatted Serialize",
"ops": 460301,
"margin": 0.84,
"percentSlower": 87.18
"ops": 288369,
"margin": 9.9,
"percentSlower": 91.08
},
{
"name": "JSON5 Serialize",
"ops": 513727,
"margin": 0.55,
"percentSlower": 85.69
"ops": 352397,
"margin": 4.83,
"percentSlower": 89.1
},
{
"name": "YAML Serialize",
"ops": 88548,
"margin": 8.11,
"percentSlower": 97.53
"ops": 62474,
"margin": 23.96,
"percentSlower": 98.07
}
],
"fastest": {
Expand Down
10 changes: 5 additions & 5 deletions benchmark/results/string.chart.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</head>
<body>
<div style="max-width: 800px">
<canvas id="chart1620916305577" width="16" height="9"></canvas>
<canvas id="chart1621006754031" width="16" height="9"></canvas>
</div>
<script>
const format = (num) => {
Expand All @@ -34,10 +34,10 @@

return chunked.map((chunk) => chunk.join("")).join(" ");
};
const ctx1620916305577 = document
.getElementById("chart1620916305577")
const ctx1621006754031 = document
.getElementById("chart1621006754031")
.getContext("2d");
const chart1620916305577 = new Chart(ctx1620916305577, {
const chart1621006754031 = new Chart(ctx1621006754031, {
type: "bar",
data: {
labels: [
Expand All @@ -49,7 +49,7 @@
],
datasets: [
{
data: [57550112, 7852572, 1396539, 888957, 226473],
data: [31394766, 7029192, 1067610, 716908, 222814],
backgroundColor: [
"rgba(63, 142, 252, 0.8)",
"rgba(116, 165, 127, 0.8)",
Expand Down
Loading

0 comments on commit db77a73

Please sign in to comment.