import { Config , CosmeticFilter , FiltersEngine , NetworkFilter , parseFilters , Request , tokenize , } from '@cliqz/adblocker' ; import { createEngine , domains500 } from './utils' ; export function benchEngineCreation ( { lists , resources } ) { return createEngine ( lists , resources , { loadCosmeticFilters : true , loadNetworkFilters : true , optimizeAOT : false , } ) ; } export function benchEngineSerialization ( { engine } ) { return engine . serialize ( ) ; } export function benchEngineDeserialization ( { serialized , } ) { if ( serialized !== undefined ) { return FiltersEngine . deserialize ( serialized ) ; } return undefined ; } export function benchStringTokenize ( { filters } ) { let dummy = 0 ; for ( let i = 0 ; i < filters . length ; i += 1 ) { dummy = ( dummy + tokenize ( filters [ i ] ) . length ) >>> 0 ; } return dummy ; } export function benchParsingImpl ( lists , options ) { return parseFilters ( lists , options ) ; } export function benchCosmeticsFiltersParsing ( { combinedLists } ) { return benchParsingImpl ( combinedLists , { loadCosmeticFilters : true , loadNetworkFilters : false , } ) ; } export function benchNetworkFiltersParsing ( { combinedLists } ) { return benchParsingImpl ( combinedLists , { loadCosmeticFilters : false , loadNetworkFilters : true , } ) ; } export function benchGetNetworkTokens ( { networkFilters } ) { let dummy = 0 ; for ( let i = 0 ; i < networkFilters . length ; i += 1 ) { dummy = ( dummy + networkFilters [ i ] . getTokens ( ) . length ) >>> 0 ; } return dummy ; } export function benchGetCosmeticTokens ( { cosmeticFilters , } ) { let dummy = 0 ; for ( let i = 0 ; i < cosmeticFilters . length ; i += 1 ) { dummy = ( dummy + cosmeticFilters [ i ] . getTokens ( ) . length ) >>> 0 ; } return dummy ; } export function benchGetCosmeticsFilters ( { engine } ) { for ( let i = 0 ; i < domains500 . length ; i += 1 ) { const domain = domains500 [ i ] ; engine . getCosmeticsFilters ( { domain , hostname : domain , url : `https://${ domain }` , } ) ; } } export function benchRequestParsing ( { requests , } ) { for ( let i = 0 ; i < requests . length ; i += 1 ) { const { url , frameUrl , cpt } = requests [ i ] ; Request . fromRawDetails ( { sourceUrl : frameUrl , type : cpt , url , } ) ; } }