Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object Signatures
(version: 0)
Unique string for object by value
Comparing performance of:
JSON.stringify vs Generic signature builder vs Custom signature builder
Created:
9 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var shapes = []; for ( let i = 0; i < 100; i++ ) { shapes.push( { position: { x: Math.random(), y: Math.random() }, width: Math.random(), height: Math.random(), points: [ { x: Math.random(), y: Math.random() }, { x: Math.random(), y: Math.random() }, { x: Math.random(), y: Math.random() }, { x: Math.random(), y: Math.random() }, ] } ); } function sortObjectProperties( objKey, val ) { var normalized, keys, i, len; if ( !Array.isArray( val ) && Object( val ) === val ) { normalized = {}; keys = Object.keys( val ).sort(); i = 0; len = keys.length; for ( ; i < len; i += 1 ) { normalized[keys[i]] = val[keys[i]]; } return normalized; } else { return val; } } function recursiveSortedSignature( o ) { const keys = Object.keys( o ).sort(); let sig = ''; for ( let k of keys ) { let v = o[k]; if ( Object( v ) === v ) { v = recursiveSortedSignature( v ); } sig += `(${k}:${v})`; } return sig; } function customSignature( o ) { const { position: { x, y }, width, height, points } = o; let pts = ''; for ( let point of points ) { pts += `(${point.x}x${point.y})`; } return `@(${x},${y})#(${width},${height})*${pts}`; }
Tests:
JSON.stringify
for ( let shape of shapes ) { JSON.stringify( val, sortObjectProperties ); }
Generic signature builder
for ( let shape of shapes ) { recursiveSortedSignature( shape ); }
Custom signature builder
for ( let shape of shapes ) { customSignature( shape ); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
JSON.stringify
Generic signature builder
Custom signature builder
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!
Related benchmarks:
Object.values vs for in loop
Unique Lodash vs Set
Object.values vs for in loop vs for loop
Object.values vs for in loop vs for loop v2
Set (Lodash vs Lodash/fp vs Immutable) comp. test
Comments
Confirm delete:
Do you really want to delete benchmark?