<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.min.js'></script>
var test = 'lkjskljdlskjdlsdjslkdjsljdlksjd'
_.toUpper(test)
test.toUpperCase()
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
lodash toUpper | |
native toUpperCase |
Test name | Executions per second |
---|---|
lodash toUpper | 5575591.0 Ops/sec |
native toUpperCase | 11090025.0 Ops/sec |
Let's break down the benchmark and explain what's being tested.
Overview
The benchmark compares two approaches: using the built-in toUpperCase()
method of JavaScript strings (the "native" approach) versus using the _.toUpper()
function from the Lodash library. The goal is to measure which approach is faster.
Options compared
There are only two options being compared:
toUpperCase()
method, which is a part of the JavaScript language._.toUpper()
function from the Lodash library, a popular utility library for JavaScript.Pros and Cons
Library usage
In this benchmark, the _.toUpper()
function from the Lodash library is used. The Lodash library provides a collection of high-quality, consistently-tested functions that make common programming tasks easier and more efficient. In this case, it's being used to provide a more flexible alternative to the built-in toUpperCase()
method.
Special JS feature or syntax
There are no special JavaScript features or syntax being tested in this benchmark. The focus is solely on comparing two approaches: using the native toUpperCase()
method versus using the Lodash library.
Other alternatives
If you wanted to modify this benchmark to compare other approaches, here are some alternative options:
.trim()
vs. the native replace()
method).toUpperCase()
method._.toUpper()
with different input lengths or character sets).Keep in mind that when modifying the benchmark, it's essential to ensure that any new alternatives are still representative of real-world use cases and provide meaningful results.