ChandraShekharAazad
ChandraShekharAazad

Reputation: 101

Calling Match Template in Promise.All No Performace Improvement?

I am using OpenCV4NodeJS-prebuilt for my project to use match template.

I Created Two Files one being Index.js and other named matchTemlate.js

In Index.js i call match template:

const { matchTemplate } = require("./matchTemplate");
...

let a = async function () {

  let tm = performance.now();
  try {
    await Promise.all([
      matchTemplate(baseImage, templateR),
      matchTemplate(baseImage, templateL)
    ]).then(result => {
      const c = result.map((ob) => (ob.C)) // confidence
      top = c[0] > c[1] ? result[0].Y + 8 : result[1].Y + 11
    })
  } catch (error) {
    console.log(error)
  }
  tm = performance.now() - tm;

  console.log(tm)
} 

and this is matchTemplate.js

const cv = require('opencv4nodejs-prebuilt')

exports.matchTemplate = async function (inputFile, templateImage) {
    // eslint-disable-next-line no-unused-expressions
    const matS = await cv.imdecodeAsync(templateImage)

    console.time('templateMatching')
    const matched = inputFile.matchTemplate(matS, 3)
    console.timeEnd('templateMatching')

    const minMax = matched.minMaxLoc()
    return ({ Y: minMax.maxLoc.y, C: minMax.maxVal })
}
 

The log output of matchTemplate is: templateMatching: 892.648ms templateMatching: 890.387ms

and The Log output of index.js is: TemplateMatching: 1824.8019220000133

Why there is no improvement is speed ? while the execution is done in parallel why it's still taking time equal to time taken by both ?

I tried Promise.all method to call ghostscript via gs4fb npm package and convert PDF to Image and the time improvement was there.

By time improvement i mean the difference of total time taken by Promise.all method and calling the functions one by one.

Upvotes: 0

Views: 237

Answers (0)

Related Questions