"-5".includes("-")
"-5" < 0
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Includes | |
Lt |
Test name | Executions per second |
---|---|
Includes | 39679740.0 Ops/sec |
Lt | 25395440.0 Ops/sec |
What is being tested?
MeasureThat.net is a website where users can create and run JavaScript microbenchmarks to compare the performance of different approaches to solving a specific problem.
In this case, we're looking at a simple benchmark that tests two things:
Options being compared
The options being compared are:
includes()
: This method checks if a string contains a specified value. It returns true
if the value is found, and false
otherwise.< 0
: This is a simple numerical comparison that checks if a number is less than zero.Pros and Cons of each approach
includes()
:< 0
**:Library used
There isn't a specific library being used in this benchmark, but includes()
is a built-in method of JavaScript strings. The numerical comparison < 0
uses a simple arithmetic operation that is native to most programming languages, including JavaScript.
Special JS features or syntax
None of the options require any special JavaScript features or syntax beyond what's shown. Both approaches are straightforward and don't rely on any advanced concepts.
Other alternatives
If you wanted to add more complexity to this benchmark, some alternative approaches could include:
string.prototype.search()
or number.prototype.isLessThan()
.Keep in mind that these alternatives would likely add complexity and may not be necessary for a simple benchmark like this one.