Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
ptag initialization/memory test - iloop 10000
(version: 2)
Comparing performance of:
ptag vs ctag
Created:
one year ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
const ITERATIONS = 10000; const ptag=(u,G,F,a,J,w="_id",L="_def",A="_lvl",Y="PTAG_",K="_FORCE",U={},x=()=>{},B=(I,E="s")=>(typeof I)[0]==E,C=B(globalThis,"o")?globalThis:U,i=([I,E,m],T)=>[E??C[Y+I]??m,C[Y+I+K]].map((O)=>T>3?B(O)?JSON.parse(O):O:O),[[Q,n],[V,X],[f,c],[v,k]]=[["ID",u,"{}"],["LVL",G,5],["PLG",a],["DEF",null,U]].map(i),H={debug:[5,">","#89A"],log:[4,">","#2AE"],info:[4,"i","#1AA"],check:[3,"?","#D6D"],warn:[2,"!","#F77"],error:[1,"X","#F36"],_dl:["[","]","|"],_css:["color:#0000;margin:-1px 0 -1px -1ch;padding:1px;","border-radius:2px;background:^^^;color:^^;","color:^;","border-right:2px solid ^;","color:^;font-weight:900;font-family:Menlo,Consolas,monospace;margin:-1px 0;padding:1px 3px;"],...v,...F??U,...k??U},M=(I,E=H)=>({...E,...I??H}),N=console)=>new Proxy({[w]:Q,[L]:M(),[A]:V},{get:(I,E)=>{let m=I[L]??H,T=m[E];X=C[Y+"LVL"+K];let O=~~(X??I[A]),Z=E==A||E==w||E==L?I[E]:O&&(O==-1||!T&&(E in N))?N[E]??N.log:!O||T?.[0]>O?x:null;if(!Z&&((I[E]??x)===x||0>J)){I[L]=T?m:M({[E]:[5,E,"#a58"]},m),T=I[L][E];let D=(n??I[w]??"").replace("{}",E),$=c??f,[_,b,S,P,r,W,q]=$?$(T,E,D,I):T;if(_!==T[0]){if(B(_,"f"))return _;D=B(_)?_:D}q=k?._dl??q??m._dl,W=k?._css??W??m._css;let h=J??("NO_COLOR"in C||!(P??m._fg!="")?0:3),[t,g,d]=q.map((R)=>h?`%c${R}%c`:R),[z,s,l,p,o]=W;I[E]=(N[r??E]??N.log).bind(N,t+(E==b?"*":b)+g+D+d,...h?[z,s,z,l,z+p,""].map((R)=>R?((o??"")+R).replace(/\^+/g,(j)=>(j=="^"?P??S:j=="^^"?P??m._fg:S)??"#000c"):R):[])}return Z||I[E]},set:(I,E,m)=>{I[E]=E==A?m??V:E==w?m??Q:M(m,I[L]);for(let T in I[L])I[T]=x;return!0}}); const ctag=(u,G,F,a,J,w="_id",L="_def",A="_lvl",Y="PTAG_",K="_FORCE",U={},x=()=>{},B=(I,E="s")=>(typeof I)[0]==E,C=B(globalThis,"o")?globalThis:U,c=([I,E,m],T)=>[E??C[Y+I]??m,C[Y+I+K]].map((O)=>T>3?B(O)?JSON.parse(O):O:O),[[Q,i],[V,X],[n,f],[v,k]]=[["ID",u,"{}"],["LVL",G,5],["PLG",a],["DEF",null,U]].map(c),H={debug:[5,">","#89A"],log:[4,">","#2AE"],info:[4,"i","#1AA"],check:[3,"?","#D6D"],warn:[2,"!","#F77"],error:[1,"X","#F36"],_dl:["",":",":"],_css:[" "," "," "," ","color:^;font-weight:900;font-family:Menlo,Consolas,monospace;"],...v,...F??U,...k??U},M=(I,E=H)=>({...E,...I??H}),N=console)=>new Proxy({[w]:Q,[L]:M(),[A]:V},{get:(I,E)=>{let m=I[L]??H,T=m[E];X=C[Y+"LVL"+K];let O=~~(X??I[A]),Z=E==A||E==w||E==L?I[E]:O&&(O==-1||!T&&(E in N))?N[E]??N.log:!O||T?.[0]>O?x:null;if(!Z&&((I[E]??x)===x||0>J)){I[L]=T?m:M({[E]:[5,E,"#a58"]},m),T=I[L][E];let D=(i??I[w]??"").replace("{}",E),$=f??n,[_,b,S,P,r,W,q]=$?$(T,E,D,I):T;if(_!==T[0]){if(B(_,"f"))return _;D=B(_)?_:D}q=k?._dl??q??m._dl,W=k?._css??W??m._css;let h=J??("NO_COLOR"in C||!(P??m._fg!="")?0:3),[t,g,d]=q.map((R)=>h?`%c${R}%c`:R),[z,s,l,p,o]=W;I[E]=(N[r??E]??N.log).bind(N,t+(E==b?"*":b)+g+D+d,...h?[z,s,z,l,z+p,""].map((R)=>R?((o??"")+R).replace(/\^+/g,(j)=>(j=="^"?P??S:j=="^^"?P??m._fg:S)??"#000c"):R):[])}return Z||I[E]},set:(I,E,m)=>{I[E]=E==A?m??V:E==w?m??Q:M(m,I[L]);for(let T in I[L])I[T]=x;return!0}}); const slim=(M,I,N,V,E,R='_id',z='_def',F='_lvl',S=N??{},y=[3,'?','#D6D'],J={debug:[5,'>','#89A'],log:[4,'>','#2AE'],info:[4,'i','#1AA'],check:y,warn:[2,'!','#F77'],error:[1,'X','#F36'],_fg:S._fg??'#fff',_dl:S._dl??['',':',':'],_css:S._css??[' ',' ',' ',' ','color:^;']},K=(q,j=J)=>({...j,...q??J}),G=()=>{},B=console)=>new Proxy({[R]:M??'{}',[z]:K(),[F]:I??5},{get:(q,j)=>{let f=q[z]??J,g=f[j],l=~~q[F],e=j==F||j==R||j==z?q[j]:l&&(-1==l||!g&&j in B)?B[j]??B.log:!l||g?.[0]>l?G:null;if(!e&&(q[j]??G)===G){q[z]=g?f:K({[j]:y},f);let[,l,e,c,o]=q[z][j],[_,n,s]=f._dl.map(D=>`%c${D}%c`);q[j]=(B[o??j]??B.log).bind(B,_+l+n+q[R]?.replace('{}',j)+s,...f._css.concat('').map(D=>D&&((f._css[4]??'')+D).replace(/\^+/g,r=>'^'==r?c??e:'^^'==r?c??f._fg:e)))}return e||q[j]},set:(q,j,w)=>{q[j]=j==F?w??I:j==R?w??M:K(w,q[z]);for(let j in q[z])q[j]=G;return!0}});
Tests:
ptag
for (let i = ITERATIONS-1; i > -1; i--) { const tag = ptag(String(i)); }
ctag
for (let i = ITERATIONS-1; i > -1; i--) { const tag = ctag(String(i)); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
ptag
ctag
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36
Browser/OS:
Chrome 136 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
ptag
35.0 Ops/sec
ctag
34.6 Ops/sec
Autogenerated LLM Summary
(model
gpt-4o-mini
, generated one year ago):
The benchmark defined in the provided JSON tests the performance of two JavaScript functions, `ptag` and `ctag`, which are designed for initializing operations related to some tagging or logging mechanisms. The benchmark involves executing these functions in a loop for a set number of iterations (10,000), measuring the frequency at which each function can be executed. ### Functions Tested 1. **ptag Function**: - The `ptag` function takes multiple parameters, including an identifier (`u`), a level (`G`), a plugin identifier (`F`), and several others that serve various default purposes. - It utilizes a Proxy object to intercept property accesses and logs or executes functions based on conditions. This Proxy pattern allows dynamic behavior: when properties are accessed or set on the resulting object, it can perform specific actions, such as logging messages with different levels of severity (debug, info, warn, error). - **Pros**: The use of a Proxy allows for more versatility, automatic logging, and easier debugging. It can dynamically adapt based on the state of the wrapper object. - **Cons**: Proxies can introduce overhead due to JavaScript’s internal checks and their complexity, potentially affecting performance during high-frequency calls. 2. **ctag Function**: - Similar to `ptag`, the `ctag` function also employs a Proxy for handling property accesses. - While the parameters passed are slightly modified, its overall structure and functionality parallel that of the `ptag` function. - **Pros**: The Proxy-based design gives it the same advantages as `ptag`, such as adaptiveness and the ability to provide custom behavior based on object state. - **Cons**: The same overhead and complexity risks apply as in `ptag`, possibly leading to performance penalties. ### Test Results The results show that `ptag` executed at approximately 26.56 executions per second, while `ctag` executed at about 25.18. This suggests that `ptag` has slightly better performance, possibly due to optimizations in its implementation or less overhead during execution. ### Considerations and Alternatives - **Performance Monitoring**: Both functions appear to focus on structured logging and could potentially serve in environments where tracking operations or states is crucial. However, if logging isn’t necessary for every operation, they could be simplified, potentially leading to performance gains. - **Alternative Approaches**: - **Direct Function Calls**: Instead of using Proxies, simple function calls could be made directly to achieve specific functionality (e.g., logging). While this might lead to less flexible code, it can result in improved performance due to reduced overhead. - **Minimalist Pattern**: Using direct object methods without Proxy, focusing on the necessary attributes or functions without dynamic behavior could serve well for systems where performance is critical, albeit at the cost of flexibility. - **Memoization**: For cases where the same ID might be processed multiple times, caching results could improve performance, especially in high-frequency invocation scenarios. In summary, the benchmark compares the relative performance of two encapsulated logging/tagging functions using Proxies. While they offer advanced features, their performance shows marginal differences, and there could be room for optimization by considering simpler alternatives for use cases that do not necessitate such dynamic capabilities.
Related benchmarks:
spacify
spacify test
For loop
map VS OBJ
console.log vs. ptag vs. ctag vs. slim vs. ptag no-log (logLevel=0) vs. ptag native-bypass (logLevel=-1) vs. ptag NO_COLOR
iloop - console.log vs. ptag vs. ctag vs. slim vs. ptag no-log (logLevel=0) vs. ptag native-bypass (logLevel=-1) vs. ptag NO_COLOR
console.log / ptag / ptagi / ctag / slim / ptag native-bypass / ptag NO_COLOR
iloop - console.log vs. ptag vs. ctag vs. slim vs. ptag native-bypass (logLevel=-1) vs. ptag NO_COLOR
ptag initialization
Comments
Confirm delete:
Do you really want to delete benchmark?