<script type="text/javascript" language="javascript" src="https://cdn.jsdelivr.net/npm/jsonata@1.5.4/jsonata-es5.min.js"></script>
<script type="text/javascript" language="javascript" src="https://cdn.jsdelivr.net/npm/jspath@0.4.0/jspath.min.js"></script>
<script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jmespath/0.15.0/jmespath.min.js"></script>
<script type="text/javascript" language="javascript" src="https://prototype.imin.co/eventseries-sample.js"></script>
<script type="text/javascript" language="javascript" src="http://meta.imin.co/v2.js"></script>
var get = p => o =>
p.reduce((xs, x) => {
if (Array.isArray(xs)) {
return xs.map(get([x])).filter(y => y !== null).flat();
} else {
return (xs && xs[x]) ? xs[x] : null;
}
}, o);
function flattenCollection(collectionIndex) {
if (collectionIndex.type === 'imin:CollectionIndex') {
return Object.entries(collectionIndex['imin:index']).reduce(function(map, [k,v]) {
map[k] = flattenCollection(v);
return map;
}, {});
} else if (collectionIndex.type === 'imin:Collection') {
return collectionIndex['imin:item'].reduce(function(map, item) {
map[item.id] = item;
return map;
}, {});
} else {
return collectionIndex;
}
}
var jsonataResult = jsonata('subEvent.offers.acceptedPaymentMethod').evaluate(result).join('<br />');
var simpleResult = get(['subEvent','offers','acceptedPaymentMethod'])(result).join('<br />');
var jsPathResult = JSPath.apply('.subEvent.offers.acceptedPaymentMethod', result).join('<br />');
var jmespathResult = jmespath.search(result, 'subEvent[].offers[].acceptedPaymentMethod[]').join('<br />');
result.subEvent.map(s => s.offers.map(o => o.acceptedPaymentMethod)).flat(2).join('<br />')
var jsPathResult = JSPath.apply('."imin:aggregateOffer".publicAdult{.price > 0 && .priceCurrency > "."}[-1]', result);
var jsPathResult = JSPath.apply('."imin:index"(.subClass | .enumeration).."imin:item"', window.imin.v2.meta);
var jsPathResult = JSPath.apply('."imin:index"(.subClass | .enumeration)..name', window.imin.v2.meta);
var result = flattenCollection(window.imin.v2.meta);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
jsonata | |
simple | |
jspath | |
jmespath | |
control | |
jspath+predicates | |
meta-index | |
meta-nameonly | |
meta-flatten |
Test name | Executions per second |
---|---|
jsonata | 4899.1 Ops/sec |
simple | 96776.2 Ops/sec |
jspath | 462071.5 Ops/sec |
jmespath | 166062.9 Ops/sec |
control | 243051.2 Ops/sec |
jspath+predicates | 966001.1 Ops/sec |
meta-index | 1491307.1 Ops/sec |
meta-nameonly | 1504333.2 Ops/sec |
The provided JSON represents a set of benchmark tests for comparing different libraries and approaches to query JSON data in JavaScript.
Library Overview
Library Comparison
Each test compares the performance of one or more libraries and approaches when querying JSON data. The results are represented as a series of objects, each containing information about the benchmark run, such as:
TestName
: The name of the benchmark test.RawUAString
: The User Agent string reported by the browser during the benchmark run.Browser
, DevicePlatform
, and OperatingSystem
: Information about the browser and device used during the benchmark run.ExecutionsPerSecond
: The number of executions per second for each library or approach.Approach Comparison
The tests compare different approaches to querying JSON data, including:
Key Insights
Overall, these benchmarks provide a comprehensive comparison of different libraries and approaches for querying JSON data in JavaScript, allowing developers to choose the best option for their specific use case.