Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Classes vs functions
(version: 0)
Comparing performance of:
Class vs Fn
Created:
5 years ago
by:
Guest
Jump to the latest result
Tests:
Class
var Test = /** @class */ (function () { function Test(x) { this.x = x; } Test.prototype.add = function () { var x = this.x; return new Test(Math.pow(x, 10) + Math.exp(x) + Math.sin(x) - Math.cos(x)); }; Test.prototype.subtract = function () { var x = this.x; return new Test(Math.pow(x, 10) + Math.exp(x) + Math.sin(x) - Math.cos(x)); }; Test.prototype.subtract1 = function () { var x = this.x; return new Test(Math.pow(x, 10) + Math.exp(x) + Math.sin(x) - Math.cos(x)); }; Test.prototype.subtract2 = function () { var x = this.x; return new Test(Math.pow(x, 10) + Math.exp(x) + Math.sin(x) - Math.cos(x)); }; Test.prototype.subtract3 = function () { var x = this.x; return new Test(Math.pow(x, 10) + Math.exp(x) + Math.sin(x) - Math.cos(x)); }; Test.prototype.subtract4 = function () { var x = this.x; return new Test(Math.pow(x, 10) + Math.exp(x) + Math.sin(x) - Math.cos(x)); }; Test.prototype.subtract5 = function () { var x = this.x; return new Test(Math.pow(x, 10) + Math.exp(x) + Math.sin(x) - Math.cos(x)); }; Test.prototype.subtract16 = function () { var x = this.x; return new Test(Math.pow(x, 10) + Math.exp(x) + Math.sin(x) - Math.cos(x)); }; Test.prototype.subtract26 = function () { var x = this.x; return new Test(Math.pow(x, 10) + Math.exp(x) + Math.sin(x) - Math.cos(x)); }; Test.prototype.subtract36 = function () { var x = this.x; return new Test(Math.pow(x, 10) + Math.exp(x) + Math.sin(x) - Math.cos(x)); }; Test.prototype.subtract46 = function () { var x = this.x; return new Test(Math.pow(x, 10) + Math.exp(x) + Math.sin(x) - Math.cos(x)); }; Test.prototype.add55 = function () { var x = this.x; return new Test(Math.pow(x, 10) + Math.exp(x) + Math.sin(x) - Math.cos(x)); }; Test.prototype.subtract55 = function () { var x = this.x; return new Test(Math.pow(x, 10) + Math.exp(x) + Math.sin(x) - Math.cos(x)); }; Test.prototype.subtract144 = function () { var x = this.x; return new Test(Math.pow(x, 10) + Math.exp(x) + Math.sin(x) - Math.cos(x)); }; Test.prototype.subtract233 = function () { var x = this.x; return new Test(Math.pow(x, 10) + Math.exp(x) + Math.sin(x) - Math.cos(x)); }; Test.prototype.subtract313 = function () { var x = this.x; return new Test(Math.pow(x, 10) + Math.exp(x) + Math.sin(x) - Math.cos(x)); }; Test.prototype.subtract413 = function () { var x = this.x; return new Test(Math.pow(x, 10) + Math.exp(x) + Math.sin(x) - Math.cos(x)); }; Test.prototype.subtract51 = function () { var x = this.x; return new Test(Math.pow(x, 10) + Math.exp(x) + Math.sin(x) - Math.cos(x)); }; Test.prototype.subtract161 = function () { var x = this.x; return new Test(Math.pow(x, 10) + Math.exp(x) + Math.sin(x) - Math.cos(x)); }; Test.prototype.subtract261 = function () { var x = this.x; return new Test(Math.pow(x, 10) + Math.exp(x) + Math.sin(x) - Math.cos(x)); }; Test.prototype.subtract362 = function () { var x = this.x; return new Test(Math.pow(x, 10) + Math.exp(x) + Math.sin(x) - Math.cos(x)); }; Test.prototype.subtract461 = function () { var x = this.x; return new Test(Math.pow(x, 10) + Math.exp(x) + Math.sin(x) - Math.cos(x)); }; Test.prototype.add4 = function () { var x = this.x; return new Test(Math.pow(x, 10) + Math.exp(x) + Math.sin(x) - Math.cos(x)); }; Test.prototype.subtract41 = function () { var x = this.x; return new Test(Math.pow(x, 10) + Math.exp(x) + Math.sin(x) - Math.cos(x)); }; Test.prototype.subtract14 = function () { var x = this.x; return new Test(Math.pow(x, 10) + Math.exp(x) + Math.sin(x) - Math.cos(x)); }; Test.prototype.subtract24 = function () { var x = this.x; return new Test(Math.pow(x, 10) + Math.exp(x) + Math.sin(x) - Math.cos(x)); }; Test.prototype.subtract34 = function () { var x = this.x; return new Test(Math.pow(x, 10) + Math.exp(x) + Math.sin(x) - Math.cos(x)); }; Test.prototype.subtract44 = function () { var x = this.x; return new Test(Math.pow(x, 10) + Math.exp(x) + Math.sin(x) - Math.cos(x)); }; Test.prototype.subtract54 = function () { var x = this.x; return new Test(Math.pow(x, 10) + Math.exp(x) + Math.sin(x) - Math.cos(x)); }; Test.prototype.subtract164 = function () { var x = this.x; return new Test(Math.pow(x, 10) + Math.exp(x) + Math.sin(x) - Math.cos(x)); }; Test.prototype.subtract264 = function () { var x = this.x; return new Test(Math.pow(x, 10) + Math.exp(x) + Math.sin(x) - Math.cos(x)); }; Test.prototype.subtract364 = function () { var x = this.x; return new Test(Math.pow(x, 10) + Math.exp(x) + Math.sin(x) - Math.cos(x)); }; Test.prototype.subtract446 = function () { var x = this.x; return new Test(Math.pow(x, 10) + Math.exp(x) + Math.sin(x) - Math.cos(x)); }; return Test; }()); for (var i = 0; i < 100; i++) { new Test(34235345345342342323423422334423).add(); }
Fn
function add(x) { return (Math.pow(x, 10) + Math.exp(x) + Math.sin(x) - Math.cos(x)); } for (var i = 0; i < 100; i++) { add(34235345345342342323423422334423); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Class
Fn
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:125.0) Gecko/20100101 Firefox/125.0
Browser/OS:
Firefox 125 on Mac OS X 10.15
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Class
95282.0 Ops/sec
Fn
20728696.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
It appears that this is a benchmarking result comparing the performance of two different approaches: a class-based method and a function-based method. Based on the results, the class-based approach ("Class") seems to be faster than the function-based approach ("Fn"), with an execution rate of 20728696.0 executions per second compared to 95281.9609375 executions per second. The key difference between the two approaches is the use of object-oriented programming (OOP) concepts in the class-based method, which appears to provide a performance boost. The function-based method, on the other hand, uses a simple function with no OOP overhead. It's worth noting that there are many factors that can affect the performance of these benchmarks, including hardware, software, and implementation details. However, based on this result alone, it suggests that the class-based approach may be faster than the function-based approach due to the benefits of OOP.
Related benchmarks:
Classes vs Prototype vs ES classes
function vs class method vs new function method v2
Object creation: arrow function vs. class
Object creation: arrow function vs. class with methods
Comparison of classes vs prototypes vs object literals also including the inheritance
Comments
Confirm delete:
Do you really want to delete benchmark?