fastestWayToCount

Benchmark created on


Setup

const text = `Once upon a time, in a land far, far away, there was a small village nestled between rolling hills and dense forests.

The villagers were known for their kindness and generosity, always willing to lend a hand to those in need.

Every year, they celebrated a grand festival, where the air was filled with laughter, music, and the aroma of delicious food.

In this village lived a young girl named Lily, who had a heart as big as the sky.

She loved exploring the woods, discovering new plants, and watching the animals in their natural habitat.

One day, while wandering deeper into the forest than she had ever gone before, Lily stumbled upon a hidden glade.

The glade was unlike anything she had ever seen.

The trees were taller, the flowers more vibrant, and the air seemed to sparkle with magic.

In the center of the glade stood an ancient oak tree, its trunk wide and sturdy, with branches that stretched towards the heavens.

As Lily approached the tree, she noticed a small door at its base.

Curiosity piqued, she gently pushed the door open.
Once upon a time, in a land far, far away, there was a small village nestled between rolling hills and dense forests.

The villagers were known for their kindness and generosity, always willing to lend a hand to those in need.

Every year, they celebrated a grand festival, where the air was filled with laughter, music, and the aroma of delicious food.

In this village lived a young girl named Lily, who had a heart as big as the sky.

She loved exploring the woods, discovering new plants, and watching the animals in their natural habitat.

One day, while wandering deeper into the forest than she had ever gone before, Lily stumbled upon a hidden glade.

The glade was unlike anything she had ever seen.

The trees were taller, the flowers more vibrant, and the air seemed to sparkle with magic.

In the center of the glade stood an ancient oak tree, its trunk wide and sturdy, with branches that stretched towards the heavens.

As Lily approached the tree, she noticed a small door at its base.

Curiosity piqued, she gently pushed the door open.
Once upon a time, in a land far, far away, there was a small village nestled between rolling hills and dense forests.

The villagers were known for their kindness and generosity, always willing to lend a hand to those in need.

Every year, they celebrated a grand festival, where the air was filled with laughter, music, and the aroma of delicious food.

In this village lived a young girl named Lily, who had a heart as big as the sky.

She loved exploring the woods, discovering new plants, and watching the animals in their natural habitat.

One day, while wandering deeper into the forest than she had ever gone before, Lily stumbled upon a hidden glade.

The glade was unlike anything she had ever seen.

The trees were taller, the flowers more vibrant, and the air seemed to sparkle with magic.

In the center of the glade stood an ancient oak tree, its trunk wide and sturdy, with branches that stretched towards the heavens.

As Lily approached the tree, she noticed a small door at its base.

Curiosity piqued, she gently pushed the door open.`

Test runner

Ready to run.

Testing in
TestOps/sec
split
text.split("\n").length
ready
regex match
(text.match(/\n/g) || []).length
ready
for loop
let count = 0;
for (let i = 0; i < text.length; i++) {
    if (text[i] === '\n') {
      count++;
    }
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.