perf_pyrDown.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. const isNodeJs = (typeof window) === 'undefined'? true : false;
  2. if (isNodeJs) {
  3. var Benchmark = require('benchmark');
  4. var cv = require('../../opencv');
  5. var HelpFunc = require('../perf_helpfunc');
  6. var Base = require('../base');
  7. } else {
  8. var paramsElement = document.getElementById('params');
  9. var runButton = document.getElementById('runButton');
  10. var logElement = document.getElementById('log');
  11. }
  12. function perf() {
  13. console.log('opencv.js loaded');
  14. if (isNodeJs) {
  15. global.cv = cv;
  16. global.combine = HelpFunc.combine;
  17. global.log = HelpFunc.log;
  18. global.decodeParams2Case = HelpFunc.decodeParams2Case;
  19. global.setBenchmarkSuite = HelpFunc.setBenchmarkSuite;
  20. global.addKernelCase = HelpFunc.addKernelCase;
  21. global.cvSize = Base.getCvSize();
  22. } else {
  23. enableButton();
  24. cvSize = getCvSize();
  25. }
  26. let totalCaseNum, currentCaseId;
  27. const PyrDownSize = [cvSize.sz1080p, cvSize.sz720p, cvSize.szVGA, cvSize.szQVGA, cvSize.szODD];
  28. const PyrDownType = ["CV_8UC1", "CV_8UC3", "CV_8UC4", "CV_16SC1", "CV_16SC3", "CV_16SC4", "CV_32FC1", "CV_32FC3", "CV_32FC4"];
  29. const combiPyrDown = combine(PyrDownSize, PyrDownType);
  30. function addPryDownCase(suite, type) {
  31. suite.add('pyrDown', function() {
  32. cv.pyrDown(src, dst);
  33. }, {
  34. 'setup': function() {
  35. let size = this.params.size;
  36. let matType = cv[this.params.matType];
  37. let src = new cv.Mat(size, matType);
  38. let dst = new cv.Mat((size.height + 1)/2, (size.height + 1)/2, matType)
  39. },
  40. 'teardown': function() {
  41. src.delete();
  42. dst.delete();
  43. }
  44. });
  45. }
  46. function addPyrDownModeCase(suite, combination, type) {
  47. totalCaseNum += combination.length;
  48. for (let i = 0; i < combination.length; ++i) {
  49. let size = combination[i][0];
  50. let matType = combination[i][1];
  51. let params = {size: size, matType:matType};
  52. addKernelCase(suite, params, type, addPryDownCase);
  53. }
  54. }
  55. function genBenchmarkCase(paramsContent) {
  56. let suite = new Benchmark.Suite;
  57. totalCaseNum = 0;
  58. currentCaseId = 0;
  59. if (/\([0-9]+x[0-9]+,[\ ]*CV\_\w+\)/g.test(paramsContent.toString())) {
  60. let params = paramsContent.toString().match(/\([0-9]+x[0-9]+,[\ ]*CV\_\w+\)/g)[0];
  61. let paramObjs = [];
  62. paramObjs.push({name:"size", value:"", reg:[""], index:0});
  63. paramObjs.push({name:"matType", value:"", reg:["/CV\_[0-9]+[FSUfsu]C[0-9]/"], index:1});
  64. let locationList = decodeParams2Case(params, paramObjs, pyrDownCombinations);
  65. for (let i = 0; i < locationList.length; i++){
  66. let first = locationList[i][0];
  67. let second = locationList[i][1];
  68. addPyrDownModeCase(suite, [pyrDownCombinations[first][second]], first);
  69. }
  70. } else {
  71. log("no filter or getting invalid params, run all the cases");
  72. addPyrDownModeCase(suite, combiPyrDown, 0);
  73. }
  74. setBenchmarkSuite(suite, "pyrDown", currentCaseId);
  75. log(`Running ${totalCaseNum} tests from pyrDown`);
  76. suite.run({ 'async': true }); // run the benchmark
  77. }
  78. let pyrDownCombinations = [combiPyrDown];
  79. if (isNodeJs) {
  80. const args = process.argv.slice(2);
  81. let paramsContent = '';
  82. if (/--test_param_filter=\([0-9]+x[0-9]+,[\ ]*CV\_\w+\)/g.test(args.toString())) {
  83. paramsContent = args.toString().match(/\([0-9]+x[0-9]+,[\ ]*CV\_\w+\)/g)[0];
  84. }
  85. genBenchmarkCase(paramsContent);
  86. } else {
  87. runButton.onclick = function() {
  88. let paramsContent = paramsElement.value;
  89. genBenchmarkCase(paramsContent);
  90. if (totalCaseNum !== 0) {
  91. disableButton();
  92. }
  93. }
  94. }
  95. };
  96. async function main() {
  97. if (cv instanceof Promise) {
  98. cv = await cv;
  99. perf();
  100. } else {
  101. cv.onRuntimeInitialized = perf;
  102. }
  103. }
  104. main();