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(JSON.parse(atob(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 | 121.9 Ops/sec |
no decoding | 294.3 Ops/sec |
I'll break down the provided benchmark definition and explain what's being tested, compared, and their pros and cons.
Benchmark Definition
The provided JSON represents two individual test cases:
**: This test case is testing how long it takes to decode a base64-encoded string using
atob(base64 decoding function) and then parse the resulting string with
JSON.parse`.**: This test case is testing how long it takes to simply log the
decoded` array, without any decoding or parsing.Comparison
The two test cases are being compared in terms of their execution times:
decoded
array (without decoding or parsing).Options Compared
There are two main options being compared:
atob
followed by parsing with JSON.parse
: This approach involves first encoding the decoded
array as a base64 string using btoa
, and then decoding it back to a JSON object using atob
.decoded
array is simply logged without any further processing.Pros and Cons
atob
followed by parsing with JSON.parse
:decoded
array is not in a format that can be easily used by JavaScript, as it's still in a binary format.Library and Special JS Feature
In both test cases, the JSON.parse()
function from the built-in JSON
object library is used to parse JSON data. There are no special JavaScript features or syntax being tested.
Other Alternatives
If you wanted to compare alternative approaches for decoding base64-encoded strings, some options could be:
atob
.JSON.stringify()
and then parsing with atob
, versus simply logging the decoded data.However, for this specific benchmark, the main focus is on comparing the execution times of two approaches: decoding using atob
followed by parsing with JSON.parse
, versus not decoding or parsing the data.