Skip to content

Performance

Vitaly Tomilov edited this page Mar 9, 2021 · 27 revisions

This library was written with significant focus on performance.

Testing resolvePath across NodeJS v10 - v15 shows average speed of 4,000,000 resolutions per second:

test with a string
import {resolvePath} from 'path-value';

const obj = {
    first: {
        second: {
            value: 123
        }
    }
};

const start = Date.now();

for (let i = 0; i < 1000_000; i++) {
    resolvePath(obj, 'first.second.value');
}

console.log(Date.now() - start); // ~240ms (NodeJS v15)

That's 2 times faster than with object-path library.

This figure becomes 3-4 times better still when parameterized with an array of tokens:

test with an array
import {resolvePath} from 'path-value';

const obj = {
    first: {
        second: {
            value: 123
        }
    }
};

const start = Date.now();

for (let i = 0; i < 1000_000; i++) {
    resolvePath(obj, ['first', 'second', 'value']);
}

console.log(Date.now() - start); // ~75ms (NodeJS v15)

That's about 7 times faster than with object-path library.


For maximum performance + syntax flexibility, you can run tokenizePath on the path, to convert it into array of tokens, cache it, and then reuse for resolving the value. See Verbose Syntax.


Last tested with path-value v0.9.0

Clone this wiki locally