var encoded = [];
var decoded = [];
for (var i = 0; i < 500; i++) {
decoded.push({"supports":{"moduleMove":true,"moduleDuplicate":true,"moduleDelete":true,"imageResize":true,"imageAlign":true,"imageCaption":true,"imageFullWidth":false},"fitsInContent":true,"alias":null,"isInSectionLoop":false,"imageId":Math.round(Math.random() * 10000),"imageAnimated":false,"imagePosition":1,"imageFit":true,"caption":"","link":"","linkTarget":"","imageAlt":"","linkTitle":"","iiePayload":{"zoom":2.0286,"cropXRatio":1,"cropYRatio":1,"version":1},"imageWidth":900,"imageHeight":382,"imageUrl":"https:\/\/diydev-shard01-cms.petsi.lan\/webseitendaten\/656\/563\/460\/images\/cache\/98.jpg?t=1475494410","origImageUrl":"https:\/\/diydev-shard01-cms.petsi.lan\/webseitendaten\/656\/563\/460\/images\/upload\/98.jpg?t=1475494410","origImageWidth":1600,"origImageHeight":1065,"transformedImageUrl":null,"transformedImageWidth":null,"transformedImageHeight":null,"imageMediaType":"JPEG","teaserboxWidth":900,"teaserboxHeight":700,"isFullwidth":false});
encoded.push(btoa(JSON.stringify(decoded[i])));
}
for (var j = 0; j < encoded.length; j++) {
console.log(atob(JSON.parse(encoded[j])));
}
for (var k = 0; k < decoded.length; k++) {
console.log(decoded[k]);
}
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
decoding | |
no decoding |
Test name | Executions per second |
---|---|
decoding | 0.0 Ops/sec |
no decoding | 752.9 Ops/sec |
Let's break down the provided JSON benchmark definition and its various components.
Benchmark Definition
The benchmark definition consists of two test cases:
atob
function to decode a base64-encoded string represented as a URL-safe string (btoa(JSON.stringify(decoded[i]))
). The decoded value is then logged to the console.decoded
array directly to the console without any encoding or decoding process.Library and Purpose
The atob
function (short for "ASCII to Binary") is a built-in JavaScript function that converts an ASCII-encoded string to a binary-encoded string. In this benchmark, it's used to encode the decoded[i]
values as base64 strings before sending them over the network or storing them in a database.
The btoa
function (short for "Binary to ASCII") is another built-in JavaScript function that converts a binary-encoded string to an ASCII-encoded string. In this benchmark, it's used to convert the encoded decoded[i]
values back into their original form before logging them to the console.
Options Compared
In the two test cases:
atob
function and logging the decoded value.decoded
array without any encoding or decoding process.Pros and Cons
decoded
array.Other Considerations
Alternatives
Other alternatives to consider when creating benchmarks like this one include:
Keep in mind that these alternatives can add complexity to your benchmarking process but provide valuable insights into the performance of your code under various scenarios.