Lookup Time is 8% of Load Time

Reader Danny Mashburn wrote in to follow up on the curiosity discussion. His curiosity got the better of him, and he decided to do a little more than a single, anecdotal test run of lookups versus loads.

Here’s what Danny had to say (shared with permission):

****

So your curiosity got my curiosity going. I plugged in your script in once and ran it and thought wow, thats an enormous savings in time! Then I ran it again, and got a slightly different value. Then again and again and I logged 10 results in excel and found an average and then I thought, what if I could run it 10 times automatically, or 20, or 100…
 
So I wrote this:

require(["N/record", "N/search"], function (r, s) {
    var load = [];
    var look = [];
    var ratio = [];

    for (var i = 0; i < 100; i++) {
        var t0 = performance.now()
        var customerId = r.load({
            type: r.Type.SALES_ORDER,
            id: 16536
        }).getValue({fieldId: "entity"});
        var t1 = performance.now();
        var totalLoad = t1 - t0;
        load.push(totalLoad);

        var t2 = performance.now();
        var customerId2 = s.lookupFields({
            type: r.Type.SALES_ORDER,
            id: 16536,
            columns: ["entity"]
        }).entity[0].value;
        var t3 = performance.now();
        var totalLookup = t3 - t2;
        look.push(totalLookup)
        console.log('test3');

        var ratioValue = totalLookup / totalLoad;
        ratio.push(ratioValue)
    }

    var sum = 0
    for (var j = 0; j < ratio.length; j++) {
        sum = sum + ratio[j]
    }
    var average = sum / ratio.length;

    console.log(load);
    console.log(look);
    console.log(ratio);
    console.log(average);
});

The results: 
 
The lookup time is on average a mere 8.68% of load time! 
 
Curiosity FTW.

****

Great work, Danny! The more you tinker with the API and your supporting tools, the more comfortable and confident you'll be with SuiteScript.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Related posts

January 7, 2021

Anything I wrote today about business would both feel and be inadequate. I simply can’t arrive at the words to express how I feel in this moment. So instead, here are a few helpful ...

Read More

December 20, 2020

2020 was a hundred swift kicks to the shorts and one giant kick in the ass. If you’ve lost people you love, if you’ve gotten sick or hurt, if you’ve lost your job, if ...

Read More

December 16, 2020

“I’ve been meaning to learn SuiteScript, but it’s hard to find the time …”“We’re slammed, and I just don’t have the time …”“I haven’t made the time …” All are variations of a theme ...

Read More

December 14, 2020

Last week we looked at mimicking the functionality of a REST endpoint with its own module (e.g. retrieving a User, or a list of Users, refreshing a token, etc). For complex integrations that rely on a large ...

Read More