tinybench
Version:
🔎 A simple, tiny and lightweight benchmarking library!
1,600 lines (1,599 loc) • 41.6 kB
JavaScript
//#region src/constants.ts
const e = [
1.96,
12.706204736432102,
4.3026527299112765,
3.182446305284264,
2.7764451051977996,
2.57058183661474,
2.446911848791681,
2.3646242510102997,
2.306004135033371,
2.262157162740992,
2.2281388519649385,
2.200985160082949,
2.178812829663418,
2.160368656461013,
2.1447866879169277,
2.131449545559323,
2.1199052992210112,
2.109815577833181,
2.10092204024096,
2.0930240544082634,
2.085963447265837,
2.0796138447276626,
2.073873067904015,
2.068657610419041,
2.063898561628021,
2.0595385527532946,
2.0555294386428713,
2.0518305164802837,
2.048407141795244,
2.0452296421327034,
2.042272456301238,
2.0395134463964077,
2.0369333434601016,
2.0345152974493383,
2.0322445093177186,
2.030107928250343,
2.0280940009804507,
2.0261924630291097,
2.0243941645751367,
2.0226909117347285,
2.021075382995338,
2.019540963982894,
2.0180816970958815,
2.0166921941428138,
2.0153675699129416,
2.0141033848332928,
2.012895595294589,
2.011740510475755,
2.010634754696446,
2.0095752344892093,
2.0085591097152062,
2.0075837681558824,
2.0066468031022118,
2.00574599353695,
2.0048792865665233,
2.0040447818101814,
2.003240717496698,
2.002465458054599,
2.0017174830120927,
2.0009953770482105,
2.000297821058262,
1.9996235841149783,
1.9989715162223116,
1.998340541772196,
1.9977296536259739,
1.9971379077520126,
1.9965644183594748,
1.996008353475506,
1.9954689309194023,
1.994945414632814,
1.9944371113297732,
1.9939433674345044,
1.9934635662785831,
1.9929971255321668,
1.9925434948468204,
1.9921021536898658,
1.9916726093523491,
1.9912543951146042,
1.9908470685550523,
1.9904502099893606,
1.9900634210283845,
1.9896863232444832,
1.989318556936819,
1.9889597799871794,
1.9886096667986737,
1.988267907310378,
1.9879342060816723,
1.9876082814405773,
1.987289864690939,
1.9869786993737681,
1.9866745405784685,
1.9863771543000652,
1.9860863168388938,
1.985801814239503,
1.9855234417658303,
1.9852510034099267,
1.9849843114317696,
1.9847231859278835,
1.9844674544266925,
1.9842169515086832,
1.983971518449634,
1.9837310028852815,
1.9834952584959407,
1.9832641447097104,
1.9830375264229902,
1.9828152737371547,
1.9825972617102912,
1.9823833701230178,
1.9821734832574516,
1.9819674896884745,
1.9817652820865104,
1.981566757031071,
1.9813718148344008,
1.9811803593745805,
1.9809922979375068,
1.9808075410672004,
1.980626002423938,
1.9804475986497296,
1.9802722492407063,
1.9800998764260065,
1.979930405052777,
1.9797637624769306,
1.9795998784593314,
1.97943868506709,
1.979280116579683,
1.9791241093996175,
1.9789706019673938,
1.978819534680521,
1.9786708498163625,
1.9785244914586055,
1.9783804054271532,
1.9782385392112587,
1.9780988419057237,
1.977961264150002,
1.9778257580700531,
1.9776922772228045,
1.9775607765430836,
1.977431212292894,
1.9773035420129166,
1.9771777244761224,
1.9770537196433886,
1.9769314886210223,
1.97681099362009,
1.9766921979174685,
1.9765750658185368,
1.9764595626214163,
1.9763456545827007,
1.9762333088845883,
1.9761224936033637,
1.9760131776791554,
1.9759053308869141,
1.9757989238085507,
1.975693927806187,
1.9755903149964589,
1.9754880582258323,
1.9753871310468787,
1.9752875076954728,
1.9751891630688665,
1.9750920727046015,
1.9749962127602256,
1.9749015599937723,
1.9748080917449764,
1.9747157859171882,
1.9746246209599583,
1.9745345758522659,
1.9744456300863593,
1.9743577636521858,
1.9742709570223849,
1.974185191137821,
1.9741004473936339,
1.9740167076257829,
1.9739339540980692,
1.9738521694896138,
1.9737713368827694,
1.9736914397514562,
1.9736124619498976,
1.9735343877017435,
1.9734572015895646,
1.9733808885447033,
1.9733054338374667,
1.973230823067649,
1.9731570421553692,
1.9730840773322162,
1.9730119151326795,
1.9729405423858692,
1.9728699462074992,
1.9728001139921352,
1.9727310334056907,
1.9726626923781656,
1.9725950790966158,
1.9725281819983451,
1.972461989764315,
1.9723964913127596,
1.9723316757930012,
1.9722675325794565,
1.972204051265833,
1.9721412216594971,
1.9720790337760221,
1.972017477833896,
1.9719565442493954,
1.9718962236316093,
1.9718365067776158,
1.971777384667801,
1.971718848461318,
1.9716608894916787,
1.971603499262479,
1.9715466694432433,
1.9714903918653972,
1.9714346585183509,
1.9713794615456992,
1.9713247932415296,
1.9712706460468354,
1.9712170125460335,
1.9711638854635767,
1.971111257660664,
1.9710591221320446,
1.9710074720029072,
1.97095630052586,
1.9709056010779908,
1.9708553671580111,
1.9708055923834753,
1.970756270488079,
1.9707073953190282,
1.9706589608344816,
1.9706109611010594,
1.9705633902914228,
1.9705162426819125,
1.9704695126502556,
1.9704231946733297,
1.9703772833249869,
1.9703317732739336,
1.9702866592816697,
1.9702419362004757,
1.9701975989714555,
1.9701536426226303,
1.9701100622670775,
1.9700668531011214,
1.9700240104025675,
1.9699815295289818,
1.969939405916016,
1.9698976350757686,
1.9698562125951948,
1.9698151341345516,
1.9697743954258797,
1.9697339922715287,
1.9696939205427133,
1.9696541761781068,
1.9696147551824699,
1.9695756536253115,
1.9695368676395828,
1.9694983934204007,
1.9694602272238055,
1.9694223653655467,
1.969384804219895,
1.9693475402184863,
1.9693105698491933,
1.9692738896550193,
1.9692374962330224,
1.9692013862332616,
1.9691655563577715,
1.9691300033595551,
1.9690947240416052,
1.9690597152559448,
1.9690249739026924,
1.9689904969291443,
1.968956281328883,
1.9689223241409022,
1.9688886224487527,
1.9688551733797075,
1.968821974103945,
1.9687890218337525,
1.968756313822743,
1.968723847365097,
1.9686916197948103,
1.9686596284849691,
1.9686278708470335,
1.9685963443301415,
1.968565046420423,
1.9685339746403347,
1.9685031265480044,
1.9684724997365923,
1.968442091833664,
1.968411900500579,
1.9683819234318907,
1.9683521583547587,
1.9683226030283762,
1.9682932552434063,
1.968264112821431,
1.9682351736144144,
1.9682064355041722,
1.968177896401857,
1.968149554247451,
1.9681214070092705,
1.9680934526834821,
1.9680656892936232,
1.968038114890141,
1.9680107275499321,
1.9679835253758984,
1.967956506496507,
1.9679296690653623,
1.9679030112607847,
1.9678765312853979,
1.967850227365727,
1.9678240977517998,
1.967798140716761,
1.9677723545564905,
1.967746737589231,
1.9677212881552217,
1.967696004616341,
1.967670885355754,
1.9676459287775685,
1.9676211333064957,
1.9675964973875213,
1.967572019485578,
1.967547698085227,
1.9675235316903468,
1.9674995188238256,
1.9674756580272583,
1.9674519478606556,
1.96742838690215,
1.9674049737477135,
1.9673817070108799,
1.9673585853224684,
1.9673356073303163,
1.9673127716990173,
1.9672900771096589,
1.9672675222595717,
1.9672451058620788,
1.9672228266462515,
1.9672006833566689,
1.9671786747531816,
1.9671567996106818,
1.967135056718874,
1.9671134448820529,
1.9670919629188843,
1.9670706096621893,
1.967049383958733,
1.9670282846690177,
1.9670073106670771,
1.9669864608402783,
1.966965734089124,
1.9669451293270586,
1.9669246454802793,
1.9669042814875488,
1.9668840363000124,
1.966863908881019,
1.9668438982059417,
1.966824003262006,
1.9668042230481186,
1.9667845565746986,
1.9667650028635129,
1.9667455609475144,
1.9667262298706825,
1.966707008687866,
1.9666878964646288,
1.9666688922770996,
1.9666499952118222,
1.9666312043656085,
1.9666125188453965,
1.9665939377681074,
1.9665754602605063,
1.9665570854590666,
1.9665388125098342,
1.966520640568296,
1.9665025687992495,
1.966484596376675,
1.9664667224836099,
1.9664489463120245,
1.9664312670626998,
1.9664136839451096,
1.9663961961773,
1.966378802985776,
1.9663615036053859,
1.9663442972792093,
1.9663271832584475,
1.9663101608023135,
1.966293229177927,
1.9662763876602067,
1.96625963553177,
1.9662429720828285,
1.9662263966110878,
1.9662099084216513,
1.9661935068269203,
1.9661771911465,
1.9661609607071053,
1.9661448148424667,
1.9661287528932416,
1.9661127742069229,
1.9660968781377508,
1.966081064046626,
1.966065331301024,
1.966049679274911,
1.9660341073486605,
1.9660186149089722,
1.9660032013487905,
1.9659878660672256,
1.9659726084694753,
1.9659574279667498,
1.965942323976193,
1.9659272959208094,
1.9659123432293915,
1.9658974653364458,
1.9658826616821223,
1.965867931712145,
1.9658532748777406,
1.9658386906355727,
1.9658241784476738,
1.965809737781378,
1.9657953681092573,
1.9657810689090576,
1.9657668396636336,
1.965752679860889,
1.9657385889937122,
1.9657245665599175,
1.9657106120621863,
1.9656967250080057,
1.9656829049096134,
1.9656691512839384,
1.965655463652545,
1.9656418415415793,
1.9656282844817121,
1.9656147920080864,
1.9656013636602634,
1.9655879989821707,
1.9655746975220507,
1.9655614588324102,
1.965548282469968,
1.9655351679956077,
1.9655221149743287,
1.9655091229751978,
1.9654961915712998,
1.9654833203396942,
1.9654705088613673,
1.9654577567211857,
1.965445063507854,
1.965432428813868,
1.9654198522354724,
1.9654073333726187,
1.9653948718289207,
1.9653824672116142,
1.9653701191315152,
1.9653578272029781,
1.9653455910438589,
1.9653334102754718,
1.9653212845225516,
1.9653092134132164,
1.9652971965789277,
1.9652852336544535,
1.9652733242778317,
1.9652614680903338,
1.9652496647364275,
1.9652379138637432,
1.9652262151230366,
1.9652145681681563,
1.9652029726560083,
1.9651914282465226,
1.9651799346026202,
1.9651684913901803,
1.9651570982780076,
1.9651457549378,
1.9651344610441186,
1.9651232162743548,
1.9651120203087005,
1.9651008728301178,
1.9650897735243085,
1.9650787220796855,
1.9650677181873428,
1.965056761541027,
1.965045851837109,
1.965034988774555,
1.965024172054902,
1.9650134013822251,
1.9650026764631154,
1.9649919970066518,
1.9649813627243728,
1.964970773330254,
1.9649602285406784,
1.9649497280744153,
1.9649392716525922,
1.964928858998672,
1.9649184898384262,
1.9649081638999137,
1.9648978809134563,
1.9648876406116125,
1.9648774427291587,
1.9648672870030628,
1.9648571731724636,
1.9648471009786466,
1.9648370701650248,
1.9648270804771135,
1.9648171316625118,
1.964807223470879,
1.9647973556539153,
1.9647875279653397,
1.9647777401608706,
1.9647679919982053,
1.9647582832369994,
1.9647486136388483,
1.9647389829672652,
1.9647293909876653,
1.9647198374673442,
1.9647103221754598,
1.964700844883014,
1.9646914053628335,
1.9646820033895525,
1.964672638739595,
1.9646633111911553,
1.9646540205241838,
1.9646447665203655,
1.964635548963106,
1.9646263676375137,
1.9646172223303833,
1.9646081128301776,
1.9645990389270147,
1.9645900004126484,
1.9645809970804544,
1.9645720287254127,
1.9645630951440949,
1.964554196134645,
1.9645453314967691,
1.9645365010317148,
1.9645277045422602,
1.9645189418326983,
1.964510212708822,
1.964501516977911,
1.964492854448715,
1.9644842249314425,
1.9644756282377454,
1.9644670641807058,
1.964458532574823,
1.9644500332359982,
1.9644415659815229,
1.9644331306300662,
1.9644247270016604,
1.964416354917689,
1.9644080142008735,
1.9643997046752626,
1.9643914261662165,
1.9643831785003991,
1.9643749615057613,
1.9643667750115323,
1.964358618848207,
1.9643504928475335,
1.964342396842502,
1.9643343306673333,
1.9643262941574684,
1.9643182871495555,
1.9643103094814403,
1.964302360992155,
1.9642944415219068,
1.9642865509120675,
1.9642786890051633,
1.964270855644863,
1.9642630506759702,
1.9642552739444101,
1.9642475252972216,
1.9642398045825453,
1.9642321116496164,
1.9642244463487513,
1.9642168085313412,
1.9642091980498402,
1.9642016147577568,
1.964194058509645,
1.9641865291610932,
1.9641790265687171,
1.964171550590149,
1.9641641010840303,
1.9641566779100006,
1.9641492809286911,
1.964141910001714,
1.964134564991655,
1.9641272457620647,
1.9641199521774493,
1.964112684103263,
1.9641054414058998,
1.9640982239526847,
1.964091031611867,
1.9640838642526093,
1.964076721744983,
1.9640696039599586,
1.9640625107693983,
1.9640554420460483,
1.9640483976635308,
1.9640413774963374,
1.964034381419821,
1.9640274093101877,
1.9640204610444916,
1.9640135365006257,
1.9640066355573154,
1.9639997580941106,
1.963992903991381,
1.9639860731303063,
1.9639792653928712,
1.9639724806618581,
1.9639657188208401,
1.9639589797541745,
1.963952263346997,
1.963945569485213,
1.963938898055494,
1.9639322489452695,
1.96392562204272,
1.9639190172367733,
1.963912434417095,
1.963905873474085,
1.9638993342988706,
1.9638928167832999,
1.9638863208199362,
1.9638798463020526,
1.9638733931236256,
1.9638669611793291,
1.9638605503645292,
1.9638541605752786,
1.9638477917083106,
1.963841443661033,
1.9638351163315244,
1.9638288096185263,
1.9638225234214404,
1.9638162576403206,
1.96381001217587,
1.9638037869294331,
1.9637975818029945,
1.9637913966991682,
1.9637852315211985,
1.9637790861729507,
1.963772960558908,
1.9637668545841658,
1.9637607681544267,
1.963754701175997,
1.96374865355578,
1.9637426252012729,
1.9637366160205605,
1.9637306259223126,
1.9637246548157765,
1.9637187026107747,
1.9637127692177012,
1.9637068545475131,
1.9637009585117295,
1.9636950810224274,
1.9636892219922344,
1.9636833813343266,
1.963677558962424,
1.9636717547907854,
1.9636659687342057,
1.96366020070801,
1.9636544506280507,
1.9636487184107032,
1.9636430039728607,
1.963637307231933,
1.9636316281058388,
1.9636259665130043,
1.9636203223723585,
1.9636146956033296,
1.9636090861258415,
1.9636034938603082,
1.963597918727633,
1.9635923606492014,
1.9635868195468806,
1.9635812953430134,
1.9635757879604159,
1.9635702973223736,
1.9635648233526377,
1.9635593659754214,
1.9635539251153973,
1.9635485006976923,
1.9635430926478856,
1.9635377008920054,
1.9635323253565247,
1.9635269659683576,
1.9635216226548569,
1.963516295343811,
1.9635109839634397,
1.9635056884423918,
1.9635004087097414,
1.9634951446949849,
1.9634898963280374,
1.9634846635392311,
1.9634794462593101,
1.9634742444194289,
1.9634690579511493,
1.9634638867864362,
1.9634587308576554,
1.9634535900975714,
1.9634484644393435,
1.9634433538165224,
1.963438258163049,
1.96343317741325,
1.963428111501836,
1.9634230603638985,
1.9634180239349066,
1.9634130021507055,
1.9634079949475116,
1.9634030022619122,
1.9633980240308617,
1.9633930601916791,
1.963388110682045,
1.9633831754399986,
1.963378254403937,
1.9633733475126116,
1.9633684547051236,
1.9633635759209254,
1.9633587110998145,
1.9633538601819331,
1.9633490231077657,
1.9633441998181338,
1.9633393902541987,
1.9633345943574538,
1.9633298120697256,
1.96332504333317,
1.9633202880902698,
1.9633155462838343,
1.963310817856994,
1.9633061027532,
1.9633014009162226,
1.9632967122901475,
1.9632920368193745,
1.963287374448614,
1.9632827251228866,
1.9632780887875207,
1.9632734653881478,
1.963268854870705,
1.963264257181428,
1.9632596722668525,
1.9632551000738105,
1.9632505405494287,
1.963245993641126,
1.963241459296613,
1.9632369374638876,
1.963232428091235,
1.9632279311272245,
1.963223446520709,
1.9632189742208208,
1.963214514176972,
1.9632100663388516,
1.9632056306564227,
1.9632012070799227,
1.9631967955598593,
1.9631923960470097,
1.9631880084924196,
1.9631836328473993,
1.9631792690635235,
1.9631749170926298,
1.9631705768868148,
1.9631662483984351,
1.9631619315801037,
1.9631576263846882,
1.9631533327653103,
1.9631490506753435,
1.963144780068411,
1.963140520898385,
1.9631362731193833,
1.9631320366857699,
1.9631278115521522,
1.9631235976733785,
1.9631193950045382,
1.963115203500959,
1.963111023118206,
1.9631068538120793,
1.963102695538613,
1.963098548254074,
1.963094411914959,
1.963090286477995,
1.9630861719001376,
1.9630820681385661,
1.963077975150687,
1.963073892894129,
1.9630698213267435,
1.9630657604066017,
1.9630617100919938,
1.9630576703414275,
1.9630536411136277,
1.9630496223675324,
1.963045614062295,
1.963041616157278,
1.9630376286120574,
1.9630336513864166,
1.9630296844403485,
1.9630257277340504,
1.9630217812279265,
1.9630178448825841,
1.963013918658834,
1.9630100025176869,
1.9630060964203544,
1.9630022003282468,
1.9629983142029712,
1.9629944380063318,
1.962990571700327,
1.9629867152471494,
1.9629828686091835,
1.9629790317490055,
1.962975204629381,
1.9629713872132657,
1.9629675794638015,
1.962963781344317,
1.9629599928183272,
1.9629562138495296,
1.9629524444018054,
1.9629486844392179,
1.9629449339260105,
1.9629411928266058,
1.962937461105606,
1.9629337387277892,
1.9629300256581104,
1.9629263218616995,
1.9629226273038602,
1.9629189419500692,
1.9629152657659752,
1.9629115987173975,
1.9629079407703247,
1.9629042918909145,
1.9629006520454917,
1.9628970212005485,
1.9628933993227415,
1.9628897863788926,
1.9628861823359869,
1.962882587161172,
1.9628790008217571,
1.9628754232852115,
1.9628718545191641,
1.9628682944914029,
1.9628647431698727,
1.9628612005226753,
1.9628576665180681,
1.9628541411244633,
1.9628506243104265,
1.962847116044676,
1.962843616296083,
1.9628401250336684,
1.9628366422266041,
1.9628331678442101,
1.962829701855956,
1.9628262442314577,
1.9628227949404782,
1.9628193539529253,
1.962815921238852,
1.9628124967684557,
1.962809080512076,
1.9628056724401943,
1.962802272523434,
1.9627988807325591,
1.9627954970384724,
1.9627921214122162,
1.96278875382497,
1.9627853942480507,
1.9627820426529121,
1.9627786990111424,
1.9627753632944653,
1.962772035474738,
1.962768715523951,
1.962765403414227,
1.9627620991178198,
1.9627588026071152,
1.9627555138546275,
1.9627522328330012,
1.962748959515009,
1.962745693873551,
1.9627424358816548,
1.9627391855124732,
1.9627359427392859,
1.9627327075354966,
1.9627294798746329,
1.9627262597303463,
1.9627230470764099,
1.962719841886719,
1.962716644135291,
1.9627134537962623,
1.9627102708438906,
1.9627070952525512,
1.9627039269967388,
1.9627007660510651,
1.9626976123902597,
1.9626944659891674,
1.9626913268227497,
1.9626881948660826,
1.9626850700943568,
1.9626819524828756,
1.9626788420070573,
1.962675738642431,
1.9626726423646375,
1.9626695531494305,
1.962666470972672,
1.9626633958103352,
1.9626603276385024,
1.962657266433364,
1.962654212171219,
1.962651164828473,
1.962648124381639,
1.962645090807336,
1.9626420640822897,
1.9626390441833281,
1.9626360310873863,
1.9626330247715016,
1.962630025212815,
1.962627032388571,
1.9626240462761142,
1.9626210668528927,
1.9626180940964544,
1.9626151279844477,
1.9626121684946207,
1.9626092156048216,
1.9626062692929966,
1.9626033295371899,
1.9626003963155434,
1.9625974696062964,
1.9625945493877848,
1.9625916356384394,
1.9625887283367882,
1.9625858274614525,
1.962582932991149,
1.9625800449046875,
1.9625771631809725,
1.962574287799,
1.9625714187378587,
1.9625685559767294,
1.9625656994948841,
1.9625628492716856,
1.9625600052865868,
1.9625571675191313,
1.9625543359489512,
1.9625515105557676,
1.9625486913193901,
1.9625458782197165,
1.9625430712367309,
1.962540270350506,
1.9625374755412,
1.962534686789057,
1.962531904074407,
1.9625291273776646,
1.96252635667933,
1.9625235919599864,
1.962520833200302,
1.9625180803810265,
1.962515333482994,
1.9625125924871198,
1.9625098573744026,
1.9625071281259212,
1.962504404722836,
1.9625016871463874,
1.9624989753778976,
1.9624962693987664,
1.9624935691904748,
1.9624908747345817,
1.9624881860127243,
1.9624855030066184,
1.9624828256980582,
1.962480154068913,
1.962477488101131,
1.962474827776736,
1.9624721730778274,
1.962469523986581,
1.9624668804852476,
1.9624642425561525,
1.962461610181696,
1.9624589833443515,
1.9624563620266673,
1.9624537462112641,
1.9624511358808356,
1.9624485310181483,
1.9624459316060407,
1.9624433376274224,
1.9624407490652758,
1.9624381659026522,
1.9624355881226763,
1.962433015708541,
1.9624304486435091,
1.9624278869109137,
1.9624253304941575,
1.9624227793767104,
1.9624202335421121,
1.9624176929739703,
1.9624151576559599,
1.962412627571823,
1.9624101027053702,
1.9624075830404768,
1.9624050685610865,
1.962402559251207,
1.9624000550949139,
1.9623975560763454,
1.962395062179708,
1.9623925733892695,
1.9623900896893647,
1.9623876110643914,
1.9623851374988106,
1.9623826689771475,
1.96238020548399,
1.9623777470039887,
1.962375293521857,
1.9623728450223694,
1.9623704014903631,
1.9623679629107367,
1.9623655292684494,
1.9623631005485223,
1.9623606767360353,
1.9623582578161303,
1.9623558437740083,
1.9623534345949294,
1.9623510302642144,
1.9623486307672415,
1.9623462360894495,
1.962343846216334,
1.962341461133449,
1.9623390808264078,
1.9623367052808791,
1.9623343344825908,
1.962331968417326,
1.9623296070709262,
1.9623272504292881,
1.9623248984783654,
1.9623225512041673,
1.9623202085927578,
1.9623178706302578,
1.9623155373028418,
1.9623132085967403,
1.962310884498237,
1.962308564993671,
1.962306250069434,
1.9623039397119733,
1.9623016339077874,
1.9622993326434304,
1.962297035905507,
1.9622947436806755,
1.9622924559556474,
1.962290172717185,
1.9622878939521027,
1.9622856196472673,
1.962283349789597
], t = Object.freeze(() => {});
//#endregion
//#region src/event.ts
var n = class extends globalThis.Event {
get error() {
return this.#e;
}
get reason() {
return this.#t;
}
get task() {
return this.#n;
}
#e;
#t;
#n;
constructor(e, t, n) {
super(e), t != null && (this.#n = t), typeof n == "string" ? this.#t = n : n != null && (this.#e = n);
}
};
//#endregion
//#region src/utils.ts
function r(e = globalThis) {
let t = "unknown", n = "unknown";
return e.Bun || e.process && e.process.versions?.bun ? (t = "bun", n = e.Bun.version || "unknown") : e.Deno ? (t = "deno", n = e.Deno.version?.deno ?? "unknown") : e.process && e.process.release?.name === "node" ? (t = "node", n = e.process.versions?.node ?? "unknown") : e.HermesInternal ? (t = "hermes", n = e.HermesInternal.getRuntimeProperties?.()["OSS Release Version"] ?? "unknown") : i(e) && e.navigator.userAgent === "Cloudflare-Workers" ? t = "workerd" : i(e) && e.navigator.userAgent.toLowerCase().startsWith("quickjs-ng") ? (t = "quickjs-ng", n = e.navigator.userAgent.split("/")[1] ?? "unknown") : typeof e.Netlify == "object" ? t = "netlify" : typeof e.EdgeRuntime == "string" ? t = "edge-light" : e.__lagon__ ? t = "lagon" : e.fastly ? t = "fastly" : e.$262 && e.lockdown && e.AsyncDisposableStack ? t = "moddable" : e.d8 ? (t = "v8", n = typeof e.version == "function" ? e.version() : "unknown") : e.inIon && e.performance && e.performance.mozMemory ? t = "spidermonkey" : typeof e.$ == "object" && e.$ !== null && "IsHTMLDDA" in e.$ ? t = "jsc" : e.window && e.navigator && (t = "browser"), {
runtime: t,
version: n
};
}
function i(e = globalThis) {
return typeof e.navigator == "object" && e.navigator !== null && typeof e.navigator.userAgent == "string";
}
const { runtime: a, version: o } = r(), s = (e) => Number(e) / 1e6, c = (e) => Number(e) * 1e6, l = (e) => e, u = (e) => Number(e) / 1e6, d = (e) => BigInt(Math.round(e * 1e6)), f = (e, t = 5, n = 2) => {
if (e === Infinity) return "+∞";
if (e === -Infinity) return "-∞";
if (e !== e) return "NaN";
let r = Math.abs(e);
if (r >= 10 ** t) return e.toFixed();
if (r < 10 ** (t - n)) return e.toFixed(n);
let i = Math.min(Math.max(0, t - (Math.floor(Math.log10(r)) + 1)), n);
return e.toFixed(i);
}, p = (e) => e !== null && (typeof e == "object" || typeof e == "function") && typeof e.then == "function", m = (async () => {}).constructor, h = (e) => typeof e == "function" && e.constructor === m, g = (e) => {
if (e == null) return !1;
if (h(e)) return !0;
try {
let n = e(), r = p(n);
if (r) try {
n.then(t).catch(t);
} catch {}
return r;
} catch {
return !1;
}
}, _ = (e) => Array.isArray(e) && e.length !== 0, v = (e, t) => {
let n = e.length;
if (n < 10) return;
let r = 0;
for (let t of e) t === 0 && r++;
if (r * 2 > n) return "zero-dominated";
let i = Math.max(3, Math.min(10, Math.floor(n / 1e3))), a = 1;
for (let t = 1; t < n && !(e[t] !== e[t - 1] && (a++, a >= i)); t++);
if (a < i) return "low-distinct";
if (n > 100 && t === 0) return "zero-mad";
}, y = (e, t) => v(e, t) !== void 0, b = (e) => {
let t;
for (let n = 0; n < e.length; n++) {
let r = e[n];
if (!(r <= 0) && (t ??= r, e[n + 1] === r)) return r;
}
return t;
};
function x(e) {
e.sort(w);
}
const S = (e) => {
let t = e.length;
if (t === 1) return {
mean: e[0],
vr: 0
};
let n = 0, r = 0, i = 0, a = 0, o = 0;
for (; o < t;) i = e[o++], a = i - n, n += a / o, r += a * (i - n);
return {
mean: n,
vr: r / (t - 1)
};
}, C = (e, t) => {
let n = (e.length - 1) * t, r = Math.floor(n), i = e[r];
if (r + 1 >= e.length) return i;
let a = e[r + 1];
return i + (n - r) * (a - i);
}, w = (e, t) => e - t, T = (e, t = {}) => {
let { estimator: n = "median", pairs: r = 1024, warmupPairs: i = 64 } = t, { fn: a, toMs: o } = e;
if (!Number.isInteger(r) || r <= 0) return 0;
if (Number.isInteger(i) && i > 0) for (let e = 0; e < i; e++) {
let e = a();
o(a() - e);
}
let s = [];
for (let e = 0; e < r; e++) {
let e = a(), t = o(a() - e);
t > 0 && s.push(t);
}
if (s.length * 2 < r) return 0;
if (s.sort(w), n === "min") return s[0];
if (n === "p05") return s[Math.max(0, Math.ceil(s.length * .05) - 1)];
let c = s.length >> 1;
return (s.length & 1) == 1 ? s[c] : (s[c - 1] + s[c]) / 2;
}, E = (e, t) => {
let n = 0, r = e.length, i = 0;
for (; i < r;) n += (Math.abs(e[i++] - t) - n) / i;
return n;
};
function D(e, t) {
let n = e.length;
if (n === 1) return 0;
let r = n >> 1, i = n + 1 >> 1, a = 0, o = r, s, c, l, u, d, f;
for (; a <= o;) {
if (s = a + o >> 1, c = i - s, l = s === 0 ? -Infinity : t - e[r - s], d = s === r ? Infinity : t - e[r - s - 1], u = c === 0 ? -Infinity : e[r + c - 1] - t, f = c === n - r ? Infinity : e[r + c] - t, l <= f && u <= d) return n & 1 ? Math.max(l, u) : (Math.max(l, u) + Math.min(d, f)) / 2;
l > f ? o = s - 1 : a = s + 1;
}
return 0;
}
const O = (e) => D(e, C(e, .5));
function k(t, n = !1) {
let { mean: r, vr: i } = S(t), a = Math.sqrt(i), o = a / Math.sqrt(t.length), s = t.length - 1, c = e[s || 1] ?? e[0], l = o * c, u = r === 0 ? Infinity : l / Math.abs(r) * 100, d = C(t, .5);
return {
aad: E(t, r),
critical: c,
df: s,
mad: D(t, d),
max: t[s],
mean: r,
min: t[0],
moe: l,
p50: d,
p75: C(t, .75),
p99: C(t, .99),
p995: C(t, .995),
p999: C(t, .999),
rme: u,
samples: n ? t : void 0,
samplesCount: t.length,
sd: a,
sem: o,
variance: i
};
}
const A = (e, t) => {
if (!e) {
let e = Error.stackTraceLimit;
try {
Error.stackTraceLimit = 0;
let n = Error(t);
throw Error.stackTraceLimit = e, e !== 0 && Error.captureStackTrace(n, A), n;
} finally {
Error.stackTraceLimit = e;
}
}
}, j = (e) => {
switch (typeof e) {
case "function": return Error(e.name);
case "object": if (e !== null) return e instanceof Error ? e : Error(e.message ?? "");
case "undefined": return Error();
case "string": return Error(e);
default: return Error(String(e));
}
}, M = (e) => {
let t = e.result.state;
return {
"Task name": e.name,
...t === "aborted-with-statistics" || t === "completed" ? {
"Latency avg (ns)": `${f(c(e.result.latency.mean))} \xb1 ${f(e.result.latency.rme)}%`,
"Latency med (ns)": `${f(c(e.result.latency.p50))} \xb1 ${f(c(e.result.latency.mad))}`,
"Throughput avg (ops/s)": `${Math.round(e.result.throughput.mean).toString()} \xb1 ${f(e.result.throughput.rme)}%`,
"Throughput med (ops/s)": `${Math.round(e.result.throughput.p50).toString()} \xb1 ${Math.round(e.result.throughput.mad).toString()}`,
Samples: e.result.latency.samplesCount
} : t === "errored" ? {
Error: e.result.error.message,
Stack: e.result.error.stack ?? "N/A"
} : {
"Latency avg (ns)": "N/A",
"Latency med (ns)": "N/A",
"Throughput avg (ops/s)": "N/A",
"Throughput med (ops/s)": "N/A",
Samples: "N/A",
Remarks: t
},
...t === "aborted-with-statistics" && { Remarks: t }
};
}, N = async (e) => {
let { fn: t, iterations: n, limit: r, signal: i, time: a = 0, timestampProvider: o = F } = e, s = n === 0 ? r : Math.max(0, Math.min(r, n)), c = [], l = [], u = !0, d = 0, f = Number.isFinite(a) && a > 0, p = n > 0, m = 0, h = o.fn, g = p ? f ? () => u && d++ < n && (h() < m || (u = !1)) : () => u && d++ < n : f ? () => u && (h() < m || (u = !1)) : () => u, _ = (e) => {
u && l.push(e);
}, v = (e) => {
c.push(j(e));
}, y = () => u = !1;
if (i) {
if (i.aborted) return [];
i.addEventListener("abort", y);
}
let b = async () => {
for (; g();) try {
_(await t());
} catch (e) {
u = !1, v(e);
break;
}
};
f && (m = h() + o.fromMs(a));
let x = Array.from({ length: s }, () => b());
if (await Promise.allSettled(x), c.length === 0) return l;
throw c.length === 1 ? c[0] : AggregateError(c, "Multiple errors occurred during concurrent execution");
}, P = globalThis.performance.now.bind(globalThis.performance), F = {
fn: P,
fromMs: l,
name: "performanceNow",
toMs: l
}, I = globalThis.process?.hrtime?.bigint.bind(globalThis.process?.hrtime) ?? (() => {
throw Error("hrtime.bigint() is not supported in this JS environment");
}), L = () => s(Number(I())), R = {
fn: I,
fromMs: d,
name: "hrtimeNow",
toMs: u
}, z = globalThis.Bun?.nanoseconds, B = z ? {
fn: z,
fromMs: c,
name: "bunNanoseconds",
toMs: s
} : void 0;
function V(e) {
return {
fn: e,
fromMs: l,
name: "custom",
toMs: l
};
}
const H = (e = a) => e === "bun" ? B : e === "deno" ? F : e === "node" ? R : F, U = (e) => {
switch (typeof e) {
case "function": return V(e);
case "string": switch (e) {
case "auto": return H();
case "bunNanoseconds": return B ?? F;
case "hrtimeNow": return R;
default: return F;
}
case "object": return e === null ? F : (A(W(e), "Invalid Timestamp Provider object"), e);
case "undefined": return F;
default: throw Error("Invalid value for 'timestampProvider' or 'now'");
}
};
function W(e) {
return typeof e == "object" && !!e && typeof e.fn == "function" && typeof e.name == "string" && typeof e.toMs == "function" && typeof e.fromMs == "function";
}
//#endregion
//#region src/task.ts
const G = [
"afterAll",
"beforeAll",
"beforeEach",
"afterEach"
], K = ["not-started", "started"], q = { state: "not-started" }, J = { state: "aborted" }, Y = { state: "started" };
var X = class extends EventTarget {
get detectedResolution() {
return this.#r;
}
get name() {
return this.#o;
}
get result() {
return {
...this.#s,
runtime: this.#n.runtime,
runtimeVersion: this.#n.runtimeVersion,
timestampProviderName: this.#n.timestampProvider.name
};
}
get runs() {
return this.#l;
}
#e = !1;
#t;
#n;
#r = void 0;
#i;
#a;
#o;
#s = q;
#c;
#l = 0;
#u;
#d;
#f;
#p;
constructor(e, t, n, r = {}) {
super(), this.#n = e, this.#o = t, this.#i = n, this.#a = r, this.#t = r.async ?? g(n), this.#u = r.signal, this.#c = r.retainSamples ?? e.retainSamples, this.#f = e.timestampProvider, this.#d = e.timestampProvider.fn, this.#p = e.timestampProvider.toMs;
for (let e of G) this.#a[e] != null && A(typeof this.#a[e] == "function", `'${e}' must be a function if provided`);
this.reset(!1), this.#u && (this.#u.aborted ? this.#v() : this.#u.addEventListener("abort", this.#v.bind(this), { once: !0 })), this.#n.signal && (this.#n.signal.aborted ? this.#v() : this.#n.signal.addEventListener("abort", this.#v.bind(this), { once: !0 }));
}
reset(e = !0) {
this.#l = 0, this.#r = void 0, this.#s = this.#e ? J : q, e && this.dispatchEvent(new n("reset", this));
}
async run() {
if (this.#s.state !== "not-started") return this;
this.#s = { state: "started" }, this.dispatchEvent(new n("start", this)), await this.#n.setup(this, "run");
let { error: e, overriddenIndices: t, samples: r } = await this.#m("run", this.#n.time, this.#n.iterations);
return await this.#n.teardown(this, "run"), this.#b({
error: e,
latencySamples: r,
overriddenIndices: t
}), this;
}
runSync() {
if (this.#s.state !== "not-started") return this;
A(this.#n.concurrency === null, "Cannot use `concurrency` option when using `runSync`"), this.#s = Y, this.dispatchEvent(new n("start", this));
let e = this.#n.setup(this, "run");
A(!p(e), "`setup` function must be sync when using `runSync()`");
let { error: t, overriddenIndices: r, samples: i } = this.#h("run", this.#n.time, this.#n.iterations), a = this.#n.teardown(this, "run");
return A(!p(a), "`teardown` function must be sync when using `runSync()`"), this.#b({
error: t,
latencySamples: i,
overriddenIndices: r
}), this;
}
async warmup() {
if (this.#s.state !== "not-started") return;
this.dispatchEvent(new n("warmup", this)), await this.#n.setup(this, "warmup");
let { error: e } = await this.#m("warmup", this.#n.warmupTime, this.#n.warmupIterations);
await this.#n.teardown(this, "warmup"), this.#y(e);
}
warmupSync() {
if (this.#s.state !== "not-started") return;
this.dispatchEvent(new n("warmup", this));
let e = this.#n.setup(this, "warmup");
A(!p(e), "`setup` function must be sync when using `runSync()`");
let { error: t } = this.#h("warmup", this.#n.warmupTime, this.#n.warmupIterations), r = this.#n.teardown(this, "warmup");
A(!p(r), "`teardown` function must be sync when using `runSync()`"), this.#y(t);
}
async #m(e, t, n) {
try {
this.#a.beforeAll && await this.#a.beforeAll.call(this, e);
let r = 0, i = [], a = new Set(), o = async () => {
if (!this.#e) try {
this.#a.beforeEach != null && await this.#a.beforeEach.call(this, e);
let { overridden: t, taskTime: n } = this.#t ? await this.#g() : this.#_(), o = i.push(n) - 1;
t && a.add(o), r += n;
} finally {
this.#a.afterEach != null && await this.#a.afterEach.call(this, e);
}
};
if (this.#n.concurrency === "task") await N({
fn: o,
iterations: n,
limit: Math.max(1, Math.floor(this.#n.threshold)),
signal: this.#u ?? this.#n.signal,
time: t,
timestampProvider: this.#f
}), this.#l = i.length;
else for (; (r < t || i.length < n) && !this.#e;) await o();
return this.#a.afterAll != null && await this.#a.afterAll.call(this, e), _(i) ? {
overriddenIndices: a,
samples: i
} : {};
} catch (e) {
return { error: j(e) };
}
}
#h(e, t, n) {
try {
if (this.#a.beforeAll) {
let t = this.#a.beforeAll.call(this, e);
A(!p(t), "`beforeAll` function must be sync when using `runSync()`");
}
let r = 0, i = [], a = new Set(), o = () => {
if (!this.#e) try {
if (this.#a.beforeEach) {
let t = this.#a.beforeEach.call(this, e);
A(!p(t), "`beforeEach` function must be sync when using `runSync()`");
}
let { overridden: t, taskTime: n } = this.#_(), o = i.push(n) - 1;
t && a.add(o), r += n;
} finally {
if (this.#a.afterEach) {
let t = this.#a.afterEach.call(this, e);
A(!p(t), "`afterEach` function must be sync when using `runSync()`");
}
}
};
for (; (r < t || i.length < n) && !this.#e;) o();
if (this.#a.afterAll) {
let t = this.#a.afterAll.call(this, e);
A(!p(t), "`afterAll` function must be sync when using `runSync()`");
}
return _(i) ? {
overriddenIndices: a,
samples: i
} : {};
} catch (e) {
return { error: j(e) };
}
}
async #g() {
let e = this.#d(), t = await this.#i.call(this), n = this.#p(this.#d() - e), r = Z(t);
return r === void 0 ? {
overridden: !1,
taskTime: n
} : {
overridden: !0,
taskTime: r
};
}
#_() {
let e = this.#d(), t = this.#i.call(this), n = this.#p(this.#d() - e);
A(!p(t), "task function must be sync when using `runSync()`");
let r = Z(t);
return r === void 0 ? {
overridden: !1,
taskTime: n
} : {
overridden: !0,
taskTime: r
};
}
#v() {
if (this.#e = !0, K.includes(this.#s.state)) {
this.#s = J;
let e = new n("abort", this);
this.dispatchEvent(e), this.#n.dispatchEvent(e);
}
}
#y(e) {
if (e) {
this.#s = {
state: "errored",
error: e
};
let t = new n("error", this, e);
if (this.dispatchEvent(t), this.#n.dispatchEvent(t), this.#n.throws) throw e;
}
}
#b({ error: e, latencySamples: t, overriddenIndices: r }) {
if (_(t)) {
this.#l = t.length;
let e = this.#n.timerOverhead;
if (e !== void 0 && e > 0) for (let n = 0; n < t.length; n++) r?.has(n) || (t[n] = Math.max(0, t[n] - e));
let i = (r?.size ?? 0) > 0, a = i ? t.filter((e, t) => !r?.has(t)) : t;
x(t);
let o = k(t, this.#c), s;
i ? _(a) ? (x(a), this.#r = b(a), s = v(a, O(a))) : this.#r = void 0 : (this.#r = b(t), s = v(t, o.mad));
let c = o.mean, l = 0, u = [];
for (let e of t) e === 0 ? u.push(c === 0 ? 0 : 1e3 / c) : (l += e, u.push(1e3 / e));
x(u);
let d = k(u, this.#c);
if (this.#s = {
state: this.#e ? "aborted-with-statistics" : "completed",
latency: o,
period: l / this.runs,
throughput: d,
totalTime: l
}, s !== void 0) {
let e = new n("warning", this, s);
this.dispatchEvent(e), this.#n.dispatchEvent(e);
}
} else this.#e && (this.#s = J);
if (e) {
this.#s = {
state: "errored",
error: e
};
let t = new n("error", this, e);
if (this.dispatchEvent(t), this.#n.dispatchEvent(t), this.#n.throws) throw e;
}
let i = new n("cycle", this);
this.dispatchEvent(i), this.#n.dispatchEvent(i), this.dispatchEvent(new n("complete", this));
}
};
function Z(e) {
return typeof e == "object" && e && "overriddenDuration" in e && typeof e.overriddenDuration == "number" && Number.isFinite(e.overriddenDuration) && e.overriddenDuration >= 0 ? e.overriddenDuration : void 0;
}
//#endregion
//#region src/bench.ts
const Q = "`subtractTimerOverhead` cannot be used with `concurrency: \"task\"` — set `concurrency` to `null` or `\"bench\"`, or disable `subtractTimerOverhead`";
var $ = class extends EventTarget {
concurrency;
iterations;
name;
now;
retainSamples;
runtime;
runtimeVersion;
setup;
signal;
subtractTimerOverhead;
teardown;
threshold;
throws;
time;
timerOverhead;
timestampProvider;
warmup;
warmupIterations;
warmupTime;
get results() {
return this.tasks.map((e) => e.result);
}
get tasks() {
return [...this.#e.values()];
}
#e = new Map();
constructor(e = {}) {
super();
let { name: r, ...i } = e;
this.name = r, this.runtime = a, this.runtimeVersion = o, this.concurrency = i.concurrency ?? null, this.threshold = i.threshold ?? Infinity, this.time = i.time ?? 1e3, this.iterations = i.iterations ?? 64, A(i.now === void 0 || i.timestampProvider === void 0, "Cannot set both `now` and `timestampProvider` options"), this.timestampProvider = U(i.now ?? i.timestampProvider), this.now = () => this.timestampProvider.toMs(this.timestampProvider.fn()), this.warmup = i.warmup ?? !0, this.warmupIterations = i.warmupIterations ?? 16, this.warmupTime = i.warmupTime ?? 250, this.setup = i.setup ?? t, this.teardown = i.teardown ?? t, this.throws = i.throws ?? !1, i.signal != null && (this.signal = i.signal), this.retainSamples = i.retainSamples === !0, this.subtractTimerOverhead = i.subtractTimerOverhead === !0, A(!(this.subtractTimerOverhead && this.concurrency === "task"), Q);
let s = this.subtractTimerOverhead ? T(this.timestampProvider) : void 0;
s != null && (this.timerOverhead = s), this.signal && this.signal.addEventListener("abort", () => {
this.dispatchEvent(new n("abort"));
}, { once: !0 });
}
add(e, t, r = {}) {
if (this.#e.has(e)) throw Error(`Task "${e}" already exists`);
{
let i = new X(this, e, t, r);
this.#e.set(e, i), this.dispatchEvent(new n("add", i));
}
return this;
}
getTask(e) {
return this.#e.get(e);
}
remove(e) {
let t = this.getTask(e);
return t && (this.#e.delete(e), this.dispatchEvent(new n("remove", t))), this;
}
reset() {
for (let e of this.#e.values()) e.reset();
this.dispatchEvent(new n("reset"));
}
async run() {
A(!(this.subtractTimerOverhead && this.concurrency === "task"), Q), this.warmup && await this.#t(), this.dispatchEvent(new n("start"));
let e = [];
if (this.concurrency === "bench") {
let t = [];
for (let e of this.#e.values()) t.push(e.run());
e = await Promise.all(t);
} else for (let t of this.#e.values()) e.push(await t.run());
return this.dispatchEvent(new n("complete")), e;
}
runSync() {
A(this.concurrency === null, "Cannot use `concurrency` option when using `runSync`"), this.warmup && this.#n();
let e = [];
this.dispatchEvent(new n("start"));
for (let t of this.#e.values()) e.push(t.runSync());
return this.dispatchEvent(new n("complete")), e;
}
table(e = M) {
return this.tasks.map(e);
}
async #t() {
if (this.dispatchEvent(new n("warmup")), this.concurrency === "bench") {
let e = [];
for (let t of this.#e.values()) e.push(t.warmup());
await Promise.all(e);
} else for (let e of this.#e.values()) await e.warmup();
}
#n() {
this.dispatchEvent(new n("warmup"));
for (let e of this.#e.values()) e.warmupSync();
}
};
//#endregion
export { $ as Bench, X as Task, T as calibrateTimerOverhead, v as classifyTimerSaturation, y as detectTimerSaturation, b as estimateResolution, f as formatNumber, L as hrtimeNow, R as hrtimeNowTimestampProvider, c as mToNs, O as medianAbsoluteDeviation, s as nToMs, P as now, F as performanceNowTimestampProvider };