Created
November 26, 2018 11:19
-
-
Save pasaran/357f9066dbe01de51d282ba2c4c9b3f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const no = require( 'nommon' ); | |
const update = require( 'immutability-helper' ); | |
const data = { | |
foo: { | |
bar: { | |
quu: [ 1, 2, 3, 4, 5 ], | |
}, | |
status: false, | |
}, | |
}; | |
const index = 2; | |
const N = 100000; | |
let r; | |
console.time( 'immutability-helper' ); | |
for ( let i = 0; i < N; i++ ) { | |
r = update( data, { | |
foo: { | |
bar: { | |
quu: { | |
[ index ]: { | |
$set: 42, | |
}, | |
}, | |
}, | |
status: { | |
$set: true, | |
}, | |
}, | |
} ); | |
} | |
console.timeEnd( 'immutability-helper' ); | |
// console.log( JSON.stringify( r, null, 4 ) ); | |
const js1 = no.jsetter( '.foo.bar.quu[ index ]' ); | |
const js2 = no.jsetter( '.foo.status' ); | |
console.time( 'nommon1' ); | |
for ( let i = 0; i < N; i++ ) { | |
r = js1( data, { index: index }, 42 ); | |
r = js2( r, null, true ); | |
} | |
console.timeEnd( 'nommon1' ); | |
// console.log( JSON.stringify( r, null, 4 ) ); | |
console.time( 'nommon2' ); | |
for ( let i = 0; i < N; i++ ) { | |
r = jsetter( { | |
'.foo.bar.quu[ index ]': 42, | |
'.foo.status': true, | |
}, data, { index: index } ); | |
} | |
console.timeEnd( 'nommon2' ); | |
// console.log( JSON.stringify( r, null, 4 ) ); | |
// В nommon нет сейчас такого хелпера, так что пока так. | |
// | |
function jsetter( setters, data, vars) { | |
let r = data; | |
for ( let key in setters ) { | |
r = no.jsetter( key )( r, vars, setters[ key ] ); | |
} | |
return r; | |
} |
Author
pasaran
commented
Nov 26, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment