Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
JSON Builder3
(version: 2)
Comparing performance of:
JSON Template vs JSON Objects Only vs JSON String Only
Created:
3 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
//none
Script Preparation code:
//none
Tests:
JSON Template
var patientTemplate = '{\ "resourceType": "Bundle",\ "id": "bundle-example",\ "type": "transaction",\ "entry": [{\ "resource": {\ "resourceType": "Patient",\ "name": [\ {\ "family": "",\ "given": [\ ]\ }\ ]\ }\ }]\ }'; var myObj = JSON.parse(patientTemplate); myObj.entry[0].resource.name[0].family="sam"; JSON.stringify(myObj);
JSON Objects Only
var patObj = {}; patObj.resourceType = "Bundle"; patObj.id = "bundle-example"; patObj.type = "transaction"; patObj.entry = []; var oneEntry = {}; oneEntry.resourceType = "Patient"; var nameArray = []; var oneName = {}; oneName.family = "sam"; nameArray.push(oneName); oneEntry.name = nameArray; var oneResource = {}; oneResource.resource = oneEntry; patObj.entry.push(oneResource); JSON.stringify(patObj);
JSON String Only
var lastName = "sam"; var patientId = "1234"; var identifierBaseSystem = "someSystem"; var requestSystem = "requestSystem"; var requestId = "requestId"; var patientFhirId = "123-456-6789abc"; var patientGuid = "fsad-sfda-fdsafdsa"; var myChartId = "43rewqrewq-rewrewqrew"; var x = ""; x = x + '{'; x = x + ' "resourceType": "Bundle",'; x = x + ' "id": "bundle-example",'; x = x + ' "type": "transaction",'; x = x + ' "entry": [{'; x = x + ' "resource": {'; x = x + ' "resourceType": "Patient",'; x += ' "id": "'+patientId+'",'; x += ' "identifier": ['; x += ' {'; x += ' "type": {'; x += ' "coding": [{'; x += ' "system": "http://terminology.hl7.org/CodeSystem/v2-0203",'; x += ' "code": "MR",'; x += ' "display": "Medical record number"'; x += ' }'; x += ' ],'; x += ' "text": "Medical record number"'; x += ' },'; x += ' "system": "'+identifierBaseSystem+'patientMrn'+'",'; x += ' "value": "'+patientId+'"'; x += ' },'; x += ' {'; x += ' "system": "'+requestSystem+'",'; x += ' "value": "'+requestId+'"'; x += ' },'; x += ' {'; x += ' "system": "'+identifierBaseSystem+'patientFhirId'+'",'; x += ' "value": "'+patientFhirId+'"'; x += ' },'; x += ' {'; x += ' "system": "'+identifierBaseSystem+'patientGuid'+'",'; x += ' "value": "'+patientGuid+'"'; x += ' },'; x += ' {'; x += ' "system": "'+identifierBaseSystem+'patientMyChartId'+'",'; x += ' "value": "'+myChartId+'"'; x += ' }'; x += ' ],'; x = x + ' "name": ['; x = x + ' {'; x = x + ' "family": "' + lastName + '",'; x = x + ' "given": ['; x = x + ' ]'; x = x + ' }'; x = x + ' ]'; x = x + ' }'; x = x + ' }]'; x = x + '}';
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
JSON Template
JSON Objects Only
JSON String Only
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and its test cases to understand what is being tested. **Benchmark Overview** MeasureThat.net is a website that allows users to create and run JavaScript microbenchmarks. The benchmark in question is testing the performance of different approaches for creating and manipulating JSON data in JavaScript. **Test Cases** There are three test cases: 1. **JSON Template** The first test case uses a template literal to create a JSON object. The template literal is defined as `var patientTemplate = '{\\\r\n \"resourceType\": \"Bundle\",\\\r\n \"id\": \"bundle-example\",\\\r\n \"type\": \"transaction\",\\\r\n\t\"entry\": [{\\\r\n \"name\": [\r\n \"' + lastName + '\",\r\n \"' + givenName + '\"]\\\r\n }\\\r\n }]\\\r\n';`. This template literal is then used to create a JSON object that represents a patient's data. 2. **JSON Objects Only** The second test case uses plain JavaScript objects to create and manipulate the same JSON data as in the first test case. The code looks like this: `var patient = { name: [ 'lastName', 'givenName' ], ... };`. 3. **JSON String Only** The third test case creates a JSON string from scratch using only strings, without any intermediate objects or template literals. This string is used to create the same JSON object as in the first test case. **What is being tested?** The benchmark is testing the performance of these three approaches: * Creating and manipulating JSON data using template literals (Test Case 1) * Creating and manipulating JSON data using plain JavaScript objects (Test Case 2) * Creating a JSON string from scratch without any intermediate objects or template literals (Test Case 3) The benchmark measures the number of executions per second for each test case, which represents the performance of each approach. **Interpretation of Results** The results show that: * Test Case 1 (JSON Template) has the lowest execution rate of approximately 351 executions per second. * Test Case 2 (JSON Objects Only) has a moderate execution rate of around 664,948.8125 executions per second. * Test Case 3 (JSON String Only) has the highest execution rate of approximately 158,153,440 executions per second. This suggests that using template literals is the fastest approach for creating and manipulating JSON data in JavaScript, followed by using plain JavaScript objects, and then creating a JSON string from scratch.
Related benchmarks:
extend vs cloneDeep vs JSON.*
extend vs cloneDeep vs JSON.*
extend vs cloneDeep vs JSON.*
cloneDeep vs JSON.*
test bool to string
Comments
Confirm delete:
Do you really want to delete benchmark?