function ucfirst (str) { let s = str[0].toUpperCase() + str.substr(1); return s; } function ucwords1 (str) { let parts = str.split(' '); for (let i=0, l=parts.length; i ucwords1('lorem ipsum dolor sit amet, something something i am the law'), 1e6)); // three trials: 958ms, 1035ms, 975ms; avg=989.333...ms console.log(benchmark(() => ucwords2('lorem ipsum dolor sit amet, something something i am the law'), 1e6)); // three trials: 2177ms, 2237ms, 2426ms; avg=2280ms // 989.333/2280 = 0.434; ucwords1 is ~60% faster than ucwords2