June 22, 2017

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

March 3, 2021

Does the physical location of a competent employee change the amount of value they can deliver for your organization? If it does, I’d be keen to hear your story. If it does not, why ...

Read More

March 2, 2021

Today a friend and former colleague of mine – who happens to now be in a development leadership role for a NetSuite partner – was lamenting the extreme difficulty of finding and hiring NetSuite ...

Read More

March 1, 2021

Software is never finished; clients are always changing and re-prioritizing. NetSuite is ever a moving target – always updating and evolving. Market forces are always shifting and shoving, forcing new demands on your business. ...

Read More