string.includes vs. array.includes

Benchmark created on


Description

Different ways of checking a single character against inclusion.

Setup

const array = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
const string = 'abcdefghijklmnopqrstuvwxyz';

Test runner

Ready to run.

Testing in
TestOps/sec
array.includes
let i = 0;

for (const char of array) {
	if (array.includes(char)) {
		i++;
	}
}
ready
string.includes
let i = 0;

for (const char of array) {
	if (string.includes(char)) {
		i++;
	}
}
ready

Revisions

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