mirror of
https://github.com/gorhill/uBlock.git
synced 2024-09-01 16:49:39 +02:00
480 lines
112 KiB
HTML
480 lines
112 KiB
HTML
|
<!DOCTYPE html>
|
||
|
<html>
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||
|
</head>
|
||
|
<body style="font: 14px sans-serif">
|
||
|
<h1>Benchmark of hostname-lookup data structures: Set, RegExp, HNTrie</h1>
|
||
|
<p><button id="createBenchmark">Creation</button> <button id="lookupBenchmark">Lookup</button></p>
|
||
|
<div id="results-0" style="white-space:pre;font-family:mono"></div>
|
||
|
<div id="results-1" style="white-space:pre;font-family:mono"></div>
|
||
|
<div id="results-2" style="white-space:pre;font-family:mono"></div>
|
||
|
<div id="results-3" style="white-space:pre;font-family:mono"></div>
|
||
|
<div id="results-4" style="white-space:pre;font-family:mono"></div>
|
||
|
<div id="results-5" style="white-space:pre;font-family:mono"></div>
|
||
|
<div id="results-6" style="white-space:pre;font-family:mono"></div>
|
||
|
|
||
|
<!-- <script src="https://rawgithub.com/gorhill/uBlock/master/src/js/hntrie.js"></script> -->
|
||
|
<script src="https://rawcdn.githack.com/gorhill/uBlock/e83ffde5af29bd44ae529c5a60e2506970e7af34/src/js/hntrie.js"></script>
|
||
|
<script src="../src/js/hntrie.js"></script>
|
||
|
|
||
|
<script src="https://cdn.jsdelivr.net/lodash/4.17.2/lodash.min.js"></script>
|
||
|
<script src="https://cdn.jsdelivr.net/platform.js/1.3.3/platform.js"></script>
|
||
|
<script src="https://cdn.jsdelivr.net/benchmarkjs/2.1.2/benchmark.js"></script>
|
||
|
<script>
|
||
|
var domainLowCount = 'gamenguide.com|itechpost.com|parentherald.com',
|
||
|
domainMediumCount = 'anime-joy.tv|boards2go.com|celebdirtylaundry.com|celebritymozo.com|collectivelyconscious.net|dailycaller.com|destructoid.com|dumpaday.com|extratorrent.cc|fastpic.ru|firstrowau.eu|firstrowus1.eu|flash-x.tv|flashsx.tv|flashx.me|flashx.run|flashx.tv|flashx1.tv|flashxx.tv|fmovies.to|free-torrent.org|free-torrent.pw|free-torrents.org|free-torrents.pw|gamenguide.com|gofirstrow.eu|gorillavid.in|gsmarena.com|health-weekly.net|i4u.com|ifirstrow.eu|ifirstrowit.eu|imagefap.com|instanonymous.com|itechpost.com|izismile.com|jpost.com|lifehacklane.com|livescience.com|mobilenapps.com|mobipicker.com|natureworldnews.com|navbug.com|ncscooper.com|newsarama.com|newseveryday.com|nowfeed2all.eu|nowvideo.sx|okceleb.com|omgwhut.com|openload.co|opensubtitles.org|parentherald.com|pornhub.com|postimg.org|putlocker9.com|pwinsider.com|qaafa.com|shorte.st|snoopfeed.com|sportsmole.co.uk|stream-tv-series.net|stream-tv2.to|stream2watch.cc|streamgaroo.com|technobuffalo.com|the-watch-series.to|thevideo.me|thinkinghumanity.com|todayshealth.buzz|tomsguide.com|tomshardware.co.uk|tomshardware.com|tomsitpro.com|toptenz.net|tribune.com.pk|tune.pk|uberhavoc.com|universityherald.com|vcpost.com|vidmax.com|vidtodo.com|vidzi.tv|viewmixed.com|viid.me|viralands.com|webfirstrow.eu|whydontyoutrythis.com|wrestlinginc.com|wrestlingnews.co|xilfy.com|yourtango.com',
|
||
|
domainHighCount = '123videos.tv|171gifs.com|1proxy.de|2ddl.download|2ddl.ooo|300mbfilms.co|300mbfilms.org|300mbmovies4u.lol|321jav.com|353online.com|4horlover.blogspot.com|4horlover2.blogspot.com|4proxy.de|61tube.com|69sugar.com|6jav.com|6teentube.am|7starhd.com|9xmovies.site|abcmalayalam.co|abgdianci.com|adultdouga.biz|aflamfree.net|aflamtorrent.com|agarios.org|ahlamtv.com|al.ly|alantv.net|alivefoot.us|alivefootballstreaming.com|allpeliculas.com|alltube.tv|ally.sh|amabitch.com|amateur.ug|ancensored.com|andrija-i-andjelka.com|animakai.info|anime-music.info|anime-shitai.tv|anime-sugoi.com|animeado.net|animeai.org|animeai2.net|animeid.io|animelek.com|animemusicdownload.info|animesenzalimiti.com|animesonline2hd.org|animesonlinetk.info|animesorion.org|animezone.pl|anitube.es|antenasport.eu|anyanime.com|apklover.net|aquariumgays.com|arab-moviez.org|arabloads.net|arabp2p.com|archived.moe|artgifsocean.com|asianporndistrict.com|asianxv.com|assistirfilmeshd.org|assistirfilmesonline2.net|atchtheofficeonline.net|avonline.tv|avpockiehd.com|axxomovies.in|azkempire.com|aznude.com|baixarsomusica.com|bajarjuegospcgratis.com|bakacan.com|balkandownload.org|balkanje.com|bdmusicboss.net|bdsmporn.us|beautiesbondage.com|becekin.net|beelink.in|behchala.com|bersek.xyz|bestsongspk.com|big4umovies.net|bilasport.pw|bitch-show.com|bitporno.com|blackboxrepack.com|blacklionmusic.com|blogqpot.com|bludv.com|bokep2017.com|bokepcewek.net|bokepseks.co|bolly2tolly.com|bouncebreak.com|brazzershd.co|btdb.in|bugiltelanjang17.com|bypassed.cab|bypassed.plus|bypassed.team|calcioitalia.stream|camrouge.com|camwhores.co|cartoonhd.be|cartoonhd.cc|cartoonhd.globa|cartoonhd.global|cartoonth12.com|catchcoin.pw|catosports.ml|centraldeanimes.biz|cholotubex.com|cinemamkv.xyz|cinetux.net|clik.pw|cliphayho.com|cloudy.ec|coastalhut.com|columbia-xxx.com|comicporno.org|comicsmanics.com|cookiesnetfl1x.com|cooltamil.com|coroas40.com|coshurl.co|couchtuner.fr|couchtuner.nu|cricbox.net|cwtube.dj|czechmoneyteens.com|dailyuploads.net|dato.porn|datpiff.biz|dblatino.com|dclinks.info|dd-books.com|debrideco.com|demonoid.co|depedlps.blogspot.com|desixnxx.net|devil-torrents.pl|discografiascompletas.net|divxatope1.com|djmazamp3.info|dokazm.mk|donlotfile.com|download-xyz.com|downloadgameps3.com|downloadgamepsp.com|downloadgamexbox.com|dragonball-time.com|drakorindo.com|drakorindofilms.com|drhmonegyi.net|dvdwap.com|dzrepackteam.com|e-hentai.me|e-jav.com|easyxtubes.com|edmdl.com|ekasiwap.com|electro-torrent.pl|embedlink.info|embedsr.to|erodouga69.com|erostar.jp|estrenosdoramas.net|estrenosdoramas.org|etsmods.net|eurostreaming.video|exposure.pw|fagken.com|fas.li|fastdrama.co|faststream.in|faststream.ws|fbstreams.me|felipephtutoriais.com.br|filecrypt.cc|filerocks.us|filesupload.org|filmaon.com|filmclub.tv|filmehd.net|filmeserialeonline.org|filmeseseriesonline.net|filmesonline1080p.com|filmesonline4.com|filmesonlineagora.com|filmesonlineplay.com|filmesonlinex.biz|filmetraduseonline.ro|filmgur.com|filmi7.com|filminvazio.com|filmovi.eu|filmozu.net|filmuptobox.net|filsex.com|firstrowas1.cc|flashbd24.blogspot.com|flixanity.online|freeadultcomix.com|freeiptvlinks.net|freelivesports.co|freeomovie.com|freesoftwaredlul.com|fuckingsession.com|full-serie.biz|fullmaza.net|fullpinoymovies.net|futebolps2.com|fxporn.net|gameofporn.net|gamepciso.com|gamestorrent.co|garotosbrasil.com|gaycock4u.com|gaysex69.net|gibanica.club|girlswithmuscle.com|go4up.com|gogoanime.ch|goldchannelmovie.net|gottateens.com|gravuregirlz.com|grcrt.net|guasavemp3.com|hacknetfl1x.net|halacima.net|happy-foxie.com|haylike.net|hdarkzone.com|hdencoders.com|hdmovie16.ws|hdmovie24.net|hdmusic23.net|hdmusic25.com|hdmusic90.co|hdporner720.com|hdpornfull.co|hdpornfull.net|hdshows.in|hdteenvids.com|hdtube.co|hdzex.net|healthsoul.info|hentai-for.me|hentai-id.tv|hentai.to|hentaicomicsbr.net|hentaiplay.net|hentaiplus.co|hentaistream.co|her69.net|herobo.com|heymanga.me|hindimoviesonlines.net|hiper.cool|hkfree.co|homeporn.tv|hon3yhd.com|hqq.watch|hulkload.com|hyperdebrid.net|i-gay.org|icwutudidare.info|idolblog.org|ig2fap.com|igg-games.com|ightdl.
|
||
|
domainHugeCount = '101com.com|101order.com|123found.com|123freeavatars.com|180hits.de|180searchassistant.com|207.net|247media.com|24log.com|24log.de|24pm-affiliation.com|2mdn.net|2o7.net|360yield.com|4affiliate.net|4d5.net|50websads.com|518ad.com|51yes.com|600z.com|777partner.com|77tracking.com|7bpeople.com|7search.com|99count.com|a-ads.com|a-counter.kiev.ua|a.0day.kiev.ua|a.aproductmsg.com|a.consumer.net|a.mktw.net|a.sakh.com|a.ucoz.net|a.ucoz.ru|a.xanga.com|a32.g.a.yimg.com|aaddzz.com|abacho.net|abandonedclover.com|abc-ads.com|abruptroad.com|absoluteclickscom.com|abz.com|ac.rnm.ca|accounts.pkr.com.invalid|acsseo.com|actionsplash.com|actualdeals.com|actuallysheep.com|acuityads.com|acuty1adsrv.com|ad-balancer.at|ad-balancer.net|ad-center.com|ad-pay.de|ad-rotator.com|ad-server.gulasidorna.se|ad-serverparc.nl|ad-souk.com|ad-space.net|ad-tech.com|ad-up.com|ad.100.tbn.ru|ad.71i.de|ad.a8.net|ad.abcnews.com|ad.abctv.com|ad.aboutwebservices.com|ad.abum.com|ad.admitad.com|ad.afy11.net|ad.allstar.cz|ad.altervista.org|ad.amgdgt.com|ad.anuntis.com|ad.auditude.com|ad.bizo.com|ad.bnmla.com|ad.bondage.com|ad.caradisiac.com|ad.centrum.cz|ad.cgi.cz|ad.choiceradio.com|ad.clix.pt|ad.cooks.com|ad.crwdcntrl.net|ad.digitallook.com|ad.directrev.com|ad.doctissimo.fr|ad.domainfactory.de|ad.e-kolay.net|ad.eurosport.com|ad.f1cd.ru|ad.flurry.com|ad.foxnetworks.com|ad.freecity.de|ad.gate24.ch|ad.globe7.com|ad.grafika.cz|ad.hbv.de|ad.hodomobile.com|ad.httpool.com|ad.hyena.cz|ad.iinfo.cz|ad.ilove.ch|ad.infoseek.com|ad.jamba.net|ad.jamster.co.uk|ad.jetsoftware.com|ad.keenspace.com|ad.leadbolt.net|ad.liveinternet.ru|ad.lupa.cz|ad.media-servers.net|ad.mediastorm.hu|ad.mgd.de|ad.musicmatch.com|ad.nachtagenten.de|ad.nozonedata.com|ad.nttnavi.co.jp|ad.nwt.cz|ad.onad.eu|ad.pandora.tv|ad.preferances.com|ad.profiwin.de|ad.prv.pl|ad.rambler.ru|ad.reunion.com|ad.sensismediasmart.com.au|ad.seznam.cz|ad.simgames.net|ad.slutload.com|ad.smartclip.net|ad.tbn.ru|ad.technoratimedia.com|ad.thewheelof.com|ad.turn.com|ad.tv2.no|ad.twitchguru.com|ad.usatoday.com|ad.virtual-nights.com|ad.wavu.hu|ad.way.cz|ad.weatherbug.com|ad.wsod.com|ad.wz.cz|ad.xrea.com|ad.yadro.ru|ad.yourmedia.com|ad.zanox.com|ad0.bigmir.net|ad01.mediacorpsingapore.com|ad1.emediate.dk|ad1.emule-project.org|ad1.kde.cz|ad1.pamedia.com.au|ad2.iinfo.cz|ad2.linxcz.cz|ad2.lupa.cz|ad2.xrea.com|ad2flash.com|ad2games.com|ad3.iinfo.cz|ad3.pamedia.com.au|ad3.xrea.com|ad4game.com|adaction.de|adadvisor.net|adap.tv|adapt.tv|adbanner.ro|adbard.net|adblade.com|adblockanalytics.com|adboost.de.vu|adboost.net|adbooth.net|adbot.com|adbrite.com|adbroker.de|adbunker.com|adbutler.com|adbutler.de|adbuyer.com|adbuyer3.lycos.com|adcash.com|adcast.deviantart.com|adcell.de|adcenter.mdf.se|adcenter.net|adcentriconline.com|adcept.net|adclick.com|adclient.uimserv.net|adclient1.tucows.com|adcomplete.com|adconion.com|adcontent.gamespy.com|adcycle.com|add.newmedia.cz|addfreestats.com|addme.com|adecn.com|ademails.com|adengage.com|adexchangegate.com|adexchangeprediction.com|adexcite.com|adexpose.com|adext.inkclub.com|adf.ly|adfactor.nl.invalid|adfarm.mediaplex.com|adflight.com|adforce.com|adform.com|adform.net|adformdsp.net|adgardener.com|adgoto.com|adgridwork.com|adhese.be|adhese.com|adimage.guardian.co.uk|adimages.been.com|adimages.carsoup.com|adimages.go.com|adimages.homestore.com|adimages.omroepzeeland.nl|adimages.sanomawsoy.fi|adimg.cnet.com|adimg.com.com|adimg.uimserv.net|adimg1.chosun.com|adimgs.sapo.pt|adimpact.com|adincube.com|adinjector.net|adinterax.com|adisfy.com|adition.com|adition.de|adition.net|adizio.com|adjix.com|adjug.com|adjuggler.com|adjuggler.yourdictionary.com|adjustnetwork.com|adk2.com|adk2ads.tictacti.com|adland.ru|adlantic.nl|adledge.com|adlegend.com|adlog.com.com|adloox.com|adlooxtracking.com|adlure.net|admagnet.net|admailtiser.com|adman.gr|adman.in.gr|adman.otenet.gr|admanagement.ch|admanager.btopenworld.com|admanager.carsoup.com|admarketplace.net|admarvel.com|admax.nexage.com|admedia.com|admedia.ro|admeld.com|admerize.be|admeta.com|admex.com|adminder.com|adminshop.com|admized.com|admob.com|admonitor.com|ad
|
||
|
var needles = ['101com.com','101order.com','123found.com','123freeavatars.com','180hits.de','180searchassistant.com','207.net','247media.com','24log.com','24log.de','24pm-affiliation.com','2mdn.net','2o7.net','360yield.com','4affiliate.net','4d5.net','50websads.com','518ad.com','51yes.com','600z.com','777partner.com','77tracking.com','7bpeople.com','7search.com','99count.com','a-ads.com','a-counter.kiev.ua','a.0day.kiev.ua','a.aproductmsg.com','a.consumer.net','a.mktw.net','a.sakh.com','a.ucoz.net','a.ucoz.ru','a.xanga.com','a32.g.a.yimg.com','aaddzz.com','abacho.net','abandonedclover.com','abc-ads.com','abruptroad.com','absoluteclickscom.com','abz.com','ac.rnm.ca','accounts.pkr.com.invalid','acsseo.com','actionsplash.com','actualdeals.com','actuallysheep.com','acuityads.com','acuty1adsrv.com','ad-balancer.at','ad-balancer.net','ad-center.com','ad-pay.de','ad-rotator.com','ad-server.gulasidorna.se','ad-serverparc.nl','ad-souk.com','ad-space.net','ad-tech.com','ad-up.com','ad.100.tbn.ru','ad.71i.de','ad.a8.net','ad.abcnews.com','ad.abctv.com','ad.aboutwebservices.com','ad.abum.com','ad.admitad.com','ad.afy11.net','ad.allstar.cz','ad.altervista.org','ad.amgdgt.com','ad.anuntis.com','ad.auditude.com','ad.bizo.com','ad.bnmla.com','ad.bondage.com','ad.caradisiac.com','ad.centrum.cz','ad.cgi.cz','ad.choiceradio.com','ad.clix.pt','ad.cooks.com','ad.crwdcntrl.net','ad.digitallook.com','ad.directrev.com','ad.doctissimo.fr','ad.domainfactory.de','ad.e-kolay.net','ad.eurosport.com','ad.f1cd.ru','ad.flurry.com','ad.foxnetworks.com','ad.freecity.de','ad.gate24.ch','ad.globe7.com','ad.grafika.cz','ad.hbv.de','ad.hodomobile.com','ad.httpool.com','ad.hyena.cz','ad.iinfo.cz','ad.ilove.ch','ad.infoseek.com','ad.jamba.net','ad.jamster.co.uk','ad.jetsoftware.com','ad.keenspace.com','ad.leadbolt.net','ad.liveinternet.ru','ad.lupa.cz','ad.media-servers.net','ad.mediastorm.hu','ad.mgd.de','ad.musicmatch.com','ad.nachtagenten.de','ad.nozonedata.com','ad.nttnavi.co.jp','ad.nwt.cz','ad.onad.eu','ad.pandora.tv','ad.preferances.com','ad.profiwin.de','ad.prv.pl','ad.rambler.ru','ad.reunion.com','ad.sensismediasmart.com.au','ad.seznam.cz','ad.simgames.net','ad.slutload.com','ad.smartclip.net','ad.tbn.ru','ad.technoratimedia.com','ad.thewheelof.com','ad.turn.com','ad.tv2.no','ad.twitchguru.com','ad.usatoday.com','ad.virtual-nights.com','ad.wavu.hu','ad.way.cz','ad.weatherbug.com','ad.wsod.com','ad.wz.cz','ad.xrea.com','ad.yadro.ru','ad.yourmedia.com','ad.zanox.com','ad0.bigmir.net','ad01.mediacorpsingapore.com','ad1.emediate.dk','ad1.emule-project.org','ad1.kde.cz','ad1.pamedia.com.au','ad2.iinfo.cz','ad2.linxcz.cz','ad2.lupa.cz','ad2.xrea.com','ad2flash.com','ad2games.com','ad3.iinfo.cz','ad3.pamedia.com.au','ad3.xrea.com','ad4game.com','adaction.de','adadvisor.net','adap.tv','adapt.tv','adbanner.ro','adbard.net','adblade.com','adblockanalytics.com','adboost.de.vu','adboost.net','adbooth.net','adbot.com','adbrite.com','adbroker.de','adbunker.com','adbutler.com','adbutler.de','adbuyer.com','adbuyer3.lycos.com','adcash.com','adcast.deviantart.com','adcell.de','adcenter.mdf.se','adcenter.net','adcentriconline.com','adcept.net','adclick.com','adclient.uimserv.net','adclient1.tucows.com','adcomplete.com','adconion.com','adcontent.gamespy.com','adcycle.com','add.newmedia.cz','addfreestats.com','addme.com','adecn.com','ademails.com','adengage.com','adexchangegate.com','adexchangeprediction.com','adexcite.com','adexpose.com','adext.inkclub.com','adf.ly','adfactor.nl.invalid','adfarm.mediaplex.com','adflight.com','adforce.com','adform.com','adform.net','adformdsp.net','adgardener.com','adgoto.com','adgridwork.com','adhese.be','adhese.com','adimage.guardian.co.uk','adimages.been.com','adimages.carsoup.com','adimages.go.com','adimages.homestore.com','adimages.omroepzeeland.nl','adimages.sanomawsoy.fi','adimg.cnet.com','adimg.com.com','adimg.uimserv.net','adimg1.chosun.com','adimgs.sapo.pt','adimpact.com','adincube.com','adinjector.net','adinterax.com','adisfy.com','adition.com','adition.de','adition.net','adizio.com','adjix.com','adjug.com','adjuggler.com','ad
|
||
|
var randomNeedle = function() {
|
||
|
return needles[((Math.random() * 65536) & 65535) % needles.length];
|
||
|
};
|
||
|
|
||
|
/******************************************************************************/
|
||
|
|
||
|
var setBasedDictCreate = function(domainOpt) {
|
||
|
// Only one hostname
|
||
|
if ( domainOpt.indexOf('|') === -1 ) {
|
||
|
if ( domainOpt.startsWith('~') ) {
|
||
|
return domainOpt.slice(1);
|
||
|
}
|
||
|
return domainOpt;
|
||
|
}
|
||
|
|
||
|
// Multiple hostnames: use a dictionary.
|
||
|
var hostnames = domainOpt.split('|');
|
||
|
var i, hostname, dict;
|
||
|
|
||
|
// First find out whether we have a homogeneous dictionary
|
||
|
var hit = false, miss = false;
|
||
|
i = hostnames.length;
|
||
|
while ( i-- ) {
|
||
|
if ( hostnames[i].startsWith('~') ) {
|
||
|
miss = true;
|
||
|
if ( hit ) { break; }
|
||
|
} else {
|
||
|
hit = true;
|
||
|
if ( miss ) { break; }
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Heterogenous dictionary: this can happen, though VERY rarely.
|
||
|
// Spotted one occurrence in EasyList Lite (cjxlist.txt):
|
||
|
// domain=photobucket.com|~secure.photobucket.com
|
||
|
if ( hit && miss ) {
|
||
|
dict = new Map();
|
||
|
i = hostnames.length;
|
||
|
while ( i-- ) {
|
||
|
hostname = hostnames[i];
|
||
|
if ( hostname.startsWith('~') ) {
|
||
|
dict.set(hostname.slice(1), false);
|
||
|
} else {
|
||
|
dict.set(hostname, true);
|
||
|
}
|
||
|
}
|
||
|
return dict;
|
||
|
}
|
||
|
|
||
|
// Homogeneous dictionary.
|
||
|
if ( hit ) {
|
||
|
return new Set(hostnames);
|
||
|
}
|
||
|
|
||
|
dict = new Set();
|
||
|
i = hostnames.length;
|
||
|
while ( i-- ) {
|
||
|
dict.add(hostnames[i].slice(1));
|
||
|
}
|
||
|
|
||
|
return dict;
|
||
|
};
|
||
|
|
||
|
var setBasedDictTest = function(haystack, needle) {
|
||
|
var pos;
|
||
|
for (;;) {
|
||
|
if ( haystack.has(needle) ) { return true; }
|
||
|
pos = needle.indexOf('.');
|
||
|
if ( pos === -1 ) { break; }
|
||
|
needle = needle.slice(pos + 1);
|
||
|
}
|
||
|
return false;
|
||
|
};
|
||
|
|
||
|
/******************************************************************************/
|
||
|
|
||
|
var regexBasedDictCreate = function(domainOpt) {
|
||
|
// Only one hostname
|
||
|
if ( domainOpt.indexOf('|') === -1 ) {
|
||
|
if ( domainOpt.startsWith('~') ) {
|
||
|
return domainOpt.slice(1);
|
||
|
}
|
||
|
return domainOpt;
|
||
|
}
|
||
|
|
||
|
// Many hostnames.
|
||
|
var re;
|
||
|
|
||
|
// Must be in dictionary (none negated).
|
||
|
if ( domainOpt.indexOf('~') === -1 ) { // all non-negated
|
||
|
re = new RegExp('(?:^|\\.)(?:' + domainOpt.replace(/\./g, '\\.') + ')$');
|
||
|
re.exec('');
|
||
|
return re;
|
||
|
}
|
||
|
|
||
|
// Must not be in dictionary (all negated).
|
||
|
if ( reDomainOptAllNegated.test(domainOpt) ) {
|
||
|
re = new RegExp('(?:^|\\.)(?:' + domainOpt.replace(/~/g, '').replace(/\./g, '\\.') + ')$');
|
||
|
re.exec('');
|
||
|
return re;
|
||
|
}
|
||
|
|
||
|
// Heterogenous dictionary: this can happen, though VERY rarely.
|
||
|
// Spotted one occurrence in EasyList Lite (cjxlist.txt):
|
||
|
// domain=photobucket.com|~secure.photobucket.com
|
||
|
var hostnames = domainOpt.split('|'),
|
||
|
i = hostnames.length,
|
||
|
dict = new Map(),
|
||
|
hostname;
|
||
|
while ( i-- ) {
|
||
|
hostname = hostnames[i];
|
||
|
if ( hostname.startsWith('~') ) {
|
||
|
dict.set(hostname.slice(1), false);
|
||
|
} else {
|
||
|
dict.set(hostname, true);
|
||
|
}
|
||
|
}
|
||
|
return dict;
|
||
|
};
|
||
|
var reDomainOptAllNegated = /^~(?:[^\|~]+\|~)+[^\|~]+$/;
|
||
|
|
||
|
var regexBasedDictTest = function(haystack, needle) {
|
||
|
return haystack.test(needle);
|
||
|
};
|
||
|
|
||
|
/******************************************************************************/
|
||
|
|
||
|
var oldTrieBasedDictCreate = function(domainOpt) {
|
||
|
return HNTrieBuilder.fromDomainOpt(domainOpt);
|
||
|
}
|
||
|
|
||
|
var oldTrieBasedDictTest = function(haystack, needle) {
|
||
|
return haystack.matches(needle);
|
||
|
};
|
||
|
|
||
|
/******************************************************************************/
|
||
|
|
||
|
var trieBasedDictCreate = function(domainOpt) {
|
||
|
hnTrieManager.reset();
|
||
|
return hnTrieManager.fromDomainOpt(domainOpt);
|
||
|
}
|
||
|
|
||
|
var trieBasedDictTest = function(haystack, needle) {
|
||
|
return haystack.matchesJS(needle);
|
||
|
};
|
||
|
|
||
|
var trieBasedDictTestWASM = function(haystack, needle) {
|
||
|
return haystack.matchesWASM(needle);
|
||
|
};
|
||
|
|
||
|
/******************************************************************************/
|
||
|
|
||
|
var gResults = [];
|
||
|
var gDictSmall, gRegexSmall, gOldTrieSmall, gTrieSmall;
|
||
|
var gDictMedium, gRegexMedium, gOldTrieMedium, gTrieMedium;
|
||
|
var gDictLarge, gRegexLarge, gOldTrieLarge, gTrieLarge;
|
||
|
var gDictHuge, gRegexHuge, gOldTrieHuge, gTrieHuge;
|
||
|
var gWhich;
|
||
|
var gBenchmarks = [ null ];
|
||
|
|
||
|
function stdout(which, text) {
|
||
|
if ( which > 0 ) {
|
||
|
which = ((which - 1) % 3) + 1;
|
||
|
}
|
||
|
var r = document.querySelector('#results-' + which);
|
||
|
if ( text === '' ) {
|
||
|
r.innerHTML = '';
|
||
|
} else {
|
||
|
r.innerHTML += text;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function doBenchmark(which) {
|
||
|
stdout(0, '');
|
||
|
stdout(0, 'Benchmarking, the higher ops/sec the better.\n');
|
||
|
stdout(0, Benchmark.platform.toString() + '.');
|
||
|
stdout(0, '\n\n');
|
||
|
stdout(1, '');
|
||
|
stdout(2, '');
|
||
|
stdout(3, '');
|
||
|
gWhich = which;
|
||
|
gBenchmarks[gWhich].run({ 'async': true });
|
||
|
}
|
||
|
|
||
|
function nextBenchmark() {
|
||
|
stdout(gWhich, 'Done.\n\n');
|
||
|
gWhich += 1;
|
||
|
var bms = gBenchmarks[gWhich];
|
||
|
if ( bms ) {
|
||
|
bms.run({ 'async': true });
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function exitBenchmark() {
|
||
|
stdout(gWhich, 'Done.\n\n');
|
||
|
}
|
||
|
|
||
|
/******************************************************************************/
|
||
|
|
||
|
function initBenchmarks() {
|
||
|
gBenchmarks.push((function() {
|
||
|
var bms = new Benchmark.Suite();
|
||
|
bms
|
||
|
.add(' - Set-based', function() {
|
||
|
gDictSmall = setBasedDictCreate(domainLowCount);
|
||
|
})
|
||
|
.add(' - Regex-based', function() {
|
||
|
gRegexSmall = regexBasedDictCreate(domainLowCount);
|
||
|
})
|
||
|
.add(' - Trie-based (old)', function() {
|
||
|
gTrieSmall = oldTrieBasedDictCreate(domainLowCount);
|
||
|
})
|
||
|
.add(' - Trie-based', function() {
|
||
|
gTrieSmall = trieBasedDictCreate(domainLowCount);
|
||
|
})
|
||
|
.on('start', function() {
|
||
|
stdout(gWhich, '');
|
||
|
stdout(gWhich, 'Create small-size dictionary\n');
|
||
|
})
|
||
|
.on('cycle', function(event) {
|
||
|
stdout(gWhich, String(event.target) + '\n');
|
||
|
})
|
||
|
.on('complete', nextBenchmark);
|
||
|
return bms;
|
||
|
})());
|
||
|
|
||
|
gBenchmarks.push((function() {
|
||
|
var bms = new Benchmark.Suite();
|
||
|
bms
|
||
|
.add(' - Set-based', function() {
|
||
|
gDictMedium = setBasedDictCreate(domainMediumCount);
|
||
|
})
|
||
|
.add(' - Regex-based', function() {
|
||
|
gRegexMedium = regexBasedDictCreate(domainMediumCount);
|
||
|
})
|
||
|
.add(' - Trie-based (old)', function() {
|
||
|
gTrieSmall = oldTrieBasedDictCreate(domainMediumCount);
|
||
|
})
|
||
|
.add(' - Trie-based', function() {
|
||
|
gTrieMedium = trieBasedDictCreate(domainMediumCount);
|
||
|
})
|
||
|
.on('start', function() {
|
||
|
stdout(gWhich, '');
|
||
|
stdout(gWhich, 'Create medium-size dictionary\n');
|
||
|
})
|
||
|
.on('cycle', function(event) {
|
||
|
stdout(gWhich, String(event.target) + '\n');
|
||
|
})
|
||
|
.on('complete', nextBenchmark);
|
||
|
return bms;
|
||
|
})());
|
||
|
|
||
|
gBenchmarks.push((function() {
|
||
|
var bms = new Benchmark.Suite();
|
||
|
bms
|
||
|
.add(' - Set-based', function() {
|
||
|
gDictLarge = setBasedDictCreate(domainHighCount);
|
||
|
})
|
||
|
.add(' - Regex-based', function() {
|
||
|
gRegexLarge = regexBasedDictCreate(domainHighCount);
|
||
|
})
|
||
|
.add(' - Trie-based (old)', function() {
|
||
|
gTrieSmall = oldTrieBasedDictCreate(domainHighCount);
|
||
|
})
|
||
|
.add(' - Trie-based', function() {
|
||
|
gTrieLarge = trieBasedDictCreate(domainHighCount);
|
||
|
})
|
||
|
.on('start', function() {
|
||
|
stdout(gWhich, '');
|
||
|
stdout(gWhich, 'Create large-size dictionary\n');
|
||
|
})
|
||
|
.on('cycle', function(event) {
|
||
|
stdout(gWhich, String(event.target) + '\n');
|
||
|
})
|
||
|
.on('complete', exitBenchmark);
|
||
|
return bms;
|
||
|
})());
|
||
|
|
||
|
var lookupCount = 1000;
|
||
|
|
||
|
gBenchmarks.push((function() {
|
||
|
var bms = new Benchmark.Suite();
|
||
|
var needles = [];
|
||
|
bms
|
||
|
.add(' - Set-based', function() {
|
||
|
for ( var i = 0, n = needles.length; i < n; i++ ) {
|
||
|
gResults[i] = setBasedDictTest(gDictSmall, needles[i]);
|
||
|
}
|
||
|
})
|
||
|
.add(' - Regex-based', function() {
|
||
|
for ( var i = 0, n = needles.length; i < n; i++ ) {
|
||
|
gResults[i] = regexBasedDictTest(gRegexSmall, needles[i]);
|
||
|
}
|
||
|
})
|
||
|
.add(' - Trie-based (old)', function() {
|
||
|
for ( var i = 0, n = needles.length; i < n; i++ ) {
|
||
|
gResults[i] = oldTrieBasedDictTest(gOldTrieSmall, needles[i]);
|
||
|
}
|
||
|
})
|
||
|
.add(' - Trie-based JS', function() {
|
||
|
for ( var i = 0, n = needles.length; i < n; i++ ) {
|
||
|
gResults[i] = trieBasedDictTest(gTrieSmall, needles[i]);
|
||
|
}
|
||
|
})
|
||
|
.on('start', function() {
|
||
|
for ( var i = 0, n = lookupCount; i < n; i++ ) {
|
||
|
needles[i] = randomNeedle();
|
||
|
}
|
||
|
gDictSmall = setBasedDictCreate(domainLowCount);
|
||
|
gRegexSmall = regexBasedDictCreate(domainLowCount);
|
||
|
gOldTrieSmall = oldTrieBasedDictCreate(domainLowCount);
|
||
|
gTrieSmall = trieBasedDictCreate(domainLowCount);
|
||
|
stdout(gWhich, '');
|
||
|
stdout(gWhich, 'Test ' + lookupCount + ' needles against small-size dictionary\n');
|
||
|
})
|
||
|
.on('cycle', function(event) {
|
||
|
stdout(gWhich, String(event.target) + '\n');
|
||
|
})
|
||
|
.on('complete', nextBenchmark);
|
||
|
|
||
|
if ( hnTrieManager.matchesWASM !== null ) {
|
||
|
bms.add(' - Trie-based WASM', function() {
|
||
|
for ( var i = 0, n = needles.length; i < n; i++ ) {
|
||
|
gResults[i] = trieBasedDictTestWASM(gTrieSmall, needles[i]);
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
|
||
|
return bms;
|
||
|
})());
|
||
|
|
||
|
gBenchmarks.push((function() {
|
||
|
var bms = new Benchmark.Suite();
|
||
|
var needles = [];
|
||
|
bms
|
||
|
.add(' - Set-based', function() {
|
||
|
for ( var i = 0, n = needles.length; i < n; i++ ) {
|
||
|
gResults[i] = setBasedDictTest(gDictMedium, needles[i]);
|
||
|
}
|
||
|
})
|
||
|
.add(' - Regex-based', function() {
|
||
|
for ( var i = 0, n = needles.length; i < n; i++ ) {
|
||
|
gResults[i] = regexBasedDictTest(gRegexMedium, needles[i]);
|
||
|
}
|
||
|
})
|
||
|
.add(' - Trie-based (old)', function() {
|
||
|
for ( var i = 0, n = needles.length; i < n; i++ ) {
|
||
|
gResults[i] = oldTrieBasedDictTest(gOldTrieMedium, needles[i]);
|
||
|
}
|
||
|
})
|
||
|
.add(' - Trie-based JS', function() {
|
||
|
for ( var i = 0, n = needles.length; i < n; i++ ) {
|
||
|
gResults[i] = trieBasedDictTest(gTrieMedium, needles[i]);
|
||
|
}
|
||
|
})
|
||
|
.on('start', function() {
|
||
|
for ( var i = 0, n = lookupCount; i < n; i++ ) {
|
||
|
needles[i] = randomNeedle();
|
||
|
}
|
||
|
gDictMedium = setBasedDictCreate(domainMediumCount);
|
||
|
gRegexMedium = regexBasedDictCreate(domainMediumCount);
|
||
|
gOldTrieMedium = oldTrieBasedDictCreate(domainMediumCount);
|
||
|
gTrieMedium = trieBasedDictCreate(domainMediumCount);
|
||
|
stdout(gWhich, '');
|
||
|
stdout(gWhich, 'Test ' + lookupCount + ' needles against medium-size dictionary\n');
|
||
|
})
|
||
|
.on('cycle', function(event) {
|
||
|
stdout(gWhich, String(event.target) + '\n');
|
||
|
})
|
||
|
.on('complete', nextBenchmark);
|
||
|
|
||
|
if ( hnTrieManager.matchesWASM !== null ) {
|
||
|
bms.add(' - Trie-based WASM', function() {
|
||
|
for ( var i = 0, n = needles.length; i < n; i++ ) {
|
||
|
gResults[i] = trieBasedDictTestWASM(gTrieMedium, needles[i]);
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
return bms;
|
||
|
})());
|
||
|
|
||
|
gBenchmarks.push((function() {
|
||
|
var bms = new Benchmark.Suite();
|
||
|
var needles = [];
|
||
|
bms
|
||
|
.add(' - Set-based', function() {
|
||
|
for ( var i = 0, n = needles.length; i < n; i++ ) {
|
||
|
gResults[i] = setBasedDictTest(gDictLarge, needles[i]);
|
||
|
}
|
||
|
})
|
||
|
.add(' - Regex-based', function() {
|
||
|
for ( var i = 0, n = needles.length; i < n; i++ ) {
|
||
|
gResults[i] = regexBasedDictTest(gRegexLarge, needles[i]);
|
||
|
}
|
||
|
})
|
||
|
.add(' - Trie-based (old)', function() {
|
||
|
for ( var i = 0, n = needles.length; i < n; i++ ) {
|
||
|
gResults[i] = oldTrieBasedDictTest(gOldTrieLarge, needles[i]);
|
||
|
}
|
||
|
})
|
||
|
.add(' - Trie-based JS', function() {
|
||
|
for ( var i = 0, n = needles.length; i < n; i++ ) {
|
||
|
gResults[i] = trieBasedDictTest(gTrieLarge, needles[i]);
|
||
|
}
|
||
|
})
|
||
|
.on('start', function() {
|
||
|
for ( var i = 0, n = lookupCount; i < n; i++ ) {
|
||
|
needles[i] = randomNeedle();
|
||
|
}
|
||
|
gDictLarge = setBasedDictCreate(domainHighCount);
|
||
|
gRegexLarge = regexBasedDictCreate(domainHighCount);
|
||
|
gOldTrieLarge = oldTrieBasedDictCreate(domainHighCount);
|
||
|
gTrieLarge = trieBasedDictCreate(domainHighCount);
|
||
|
if ( typeof HNTrie16wasm !== 'undefined' ) {
|
||
|
gTrieLargeWasm = trieBasedWasmDictCreate(gTrieLarge);
|
||
|
}
|
||
|
stdout(gWhich, '');
|
||
|
stdout(gWhich, 'Test ' + lookupCount + ' needles against large-size dictionary\n');
|
||
|
})
|
||
|
.on('cycle', function(event) {
|
||
|
stdout(gWhich, String(event.target) + '\n');
|
||
|
})
|
||
|
.on('complete', exitBenchmark);
|
||
|
|
||
|
if ( hnTrieManager.matchesWASM !== null ) {
|
||
|
bms.add(' - Trie-based WASM', function() {
|
||
|
for ( var i = 0, n = needles.length; i < n; i++ ) {
|
||
|
gResults[i] = trieBasedDictTestWASM(gTrieLarge, needles[i]);
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
return bms;
|
||
|
})());
|
||
|
}
|
||
|
|
||
|
/******************************************************************************/
|
||
|
|
||
|
hnTrieManager.readyToUse().then(( ) => {
|
||
|
initBenchmarks();
|
||
|
});
|
||
|
|
||
|
document.getElementById('createBenchmark').onclick = function() {
|
||
|
doBenchmark(1);
|
||
|
};
|
||
|
document.getElementById('lookupBenchmark').onclick = function() {
|
||
|
doBenchmark(4);
|
||
|
};
|
||
|
</script>
|
||
|
</body>
|
||
|
</html>
|