bench/run_benchmark.js
function runMicroBenchmarks(lists, resources) {
  console.log('Run micro bench...');
  // Create adb engine to use in benchmark
  const { engine, serialized } = createEngine(lists, resources, {
    loadCosmeticFilters: true,
    loadNetworkFilters: true,
  }, true /* Also serialize engine */);

  const filters = getFiltersFromLists(lists);
  const combinedLists = filters.join('\n');
  const { networkFilters, cosmeticFilters } = parseFilters(combinedLists);
  const results = {};

  // Arguments shared among benchmarks
  const args = {
    lists,
    resources,
    engine,
    filters,
    serialized,
    networkFilters,
    cosmeticFilters,
    combinedLists,
  };

  [
    benchCosmeticsFiltersParsing,
    benchEngineCreation,
    benchEngineDeserialization,
    benchEngineSerialization,
    benchGetCosmeticTokens,
    benchGetNetworkTokens,
    benchNetworkFiltersParsing,
    benchStringHashing,
    benchStringTokenize,
    benchGetCosmeticsFilters,
  ].forEach((bench) => {
    if (bench.name.toLowerCase().includes(GREP)) {
      const suite = new Benchmark.Suite();
      suite.add(bench.name, () => bench(args)).on('cycle', (event) => {
        results[bench.name] = {
          opsPerSecond: event.target.hz,
          relativeMarginOfError: event.target.stats.rme,
          numberOfSamples: event.target.stats.sample.length,
        };
      }).run({ async: false });
    }
  });

  return {
    engineStats: {
      numFilters: engine.size,
      numCosmeticFilters: engine.cosmetics.size,
      numExceptionFilters: engine.exceptions.size,
      numImportantFilters: engine.importants.size,
      numRedirectFilters: engine.redirects.size,
    },
    microBenchmarks: results,
  };
}
function runMicroBenchmarks(lists, resources) {
  console.log('Run micro bench...');
  // Create adb engine to use in benchmark
  const { engine, serialized } = createEngine(lists, resources, {
    loadCosmeticFilters: true,
    loadNetworkFilters: true,
  }, true /* Also serialize engine */);

  const filters = getFiltersFromLists(lists);
  const combinedLists = filters.join('\n');
  const { networkFilters, cosmeticFilters } = parseFilters(combinedLists);
  const results = {};

  // Arguments shared among benchmarks
  const args = {
    lists,
    resources,
    engine,
    filters,
    serialized,
    networkFilters,
    cosmeticFilters,
    combinedLists,
  };

  [
    benchCosmeticsFiltersParsing,
    benchEngineCreation,
    benchEngineDeserialization,
    benchEngineSerialization,
    benchGetCosmeticTokens,
    benchGetNetworkTokens,
    benchNetworkFiltersParsing,
    benchStringHashing,
    benchStringTokenize,
    benchGetCosmeticsFilters,
  ].forEach((bench) => {
    if (bench.name.toLowerCase().includes(GREP)) {
      const suite = new Benchmark.Suite();
      suite.add(bench.name, () => bench(args)).on('cycle', (event) => {
        results[bench.name] = {
          opsPerSecond: event.target.hz,
          relativeMarginOfError: event.target.stats.rme,
          numberOfSamples: event.target.stats.sample.length,
        };
      }).run({ async: false });
    }
  });

  return {
    engineStats: {
      numFilters: engine.size,
      numCosmeticFilters: engine.cosmetics.size,
      numExceptionFilters: engine.exceptions.size,
      numImportantFilters: engine.importants.size,
      numRedirectFilters: engine.redirects.size,
    },
    microBenchmarks: results,
  };
}
function runMicroBenchmarks ( lists , resources ) { console . log ( 'Run micro bench...' ) ; // Create adb engine to use in benchmark const { engine , serialized } = createEngine ( lists , resources , { loadCosmeticFilters : true , loadNetworkFilters : true , } , true /* Also serialize engine */ ) ; const filters = getFiltersFromLists ( lists ) ; const combinedLists = filters . join ( '\n' ) ; const { networkFilters , cosmeticFilters } = parseFilters ( combinedLists ) ; const results = { } ; // Arguments shared among benchmarks const args = { lists , resources , engine , filters , serialized , networkFilters , cosmeticFilters , combinedLists , } ; [ benchCosmeticsFiltersParsing , benchEngineCreation , benchEngineDeserialization , benchEngineSerialization , benchGetCosmeticTokens , benchGetNetworkTokens , benchNetworkFiltersParsing , benchStringHashing , benchStringTokenize , benchGetCosmeticsFilters , ] . forEach ( ( bench ) => { if ( bench . name . toLowerCase ( ) . includes ( GREP ) ) { const suite = new Benchmark . Suite ( ) ; suite . add ( bench . name , ( ) => bench ( args ) ) . on ( 'cycle' , ( event ) => { results [ bench . name ] = { opsPerSecond : event . target . hz , relativeMarginOfError : event . target . stats . rme , numberOfSamples : event . target . stats . sample . length , } ; } ) . run ( { async : false } ) ; } } ) ; return { engineStats : { numFilters : engine . size , numCosmeticFilters : engine . cosmetics . size , numExceptionFilters : engine . exceptions . size , numImportantFilters : engine . importants . size , numRedirectFilters : engine . redirects . size , } , microBenchmarks : results , } ; }
Micro benchmarks are a set of benchmarks measuring specific aspects of the library
Micro benchmarks are a set of benchmarks measuring specific aspects of the library