I have this simple function for counting Alphabets frequency.
My code is:
function getFreq(str){
var freq={};
str.replace(/[a-z A-Z]/g, function(match){
freq[match] = (freq[match] || 0) + 1;
return match;
});
console.log(JSON.stringify(freq));
return freq;
}
var t0 = performance.now();
function doSomething(s){
getFreq(s);
};
var t1 = performance.now();
console.log("Call to doSomething took " + (t1 - t0) + " ms.")
Enter Here : <input type="text" onchange="doSomething(this.value);" />
I have want to calculate the execution speed of getFreq function after typing some text in the input box. But here dosomething function gets run even without any data in the input box and shows same execution time even after typing some data.
console.log("Call to doSomething took " + (t1 - t0) + " ms.")