I wrote "Is()" function (click here) for AutoHotKey just to test speed! (which is really slow, it takes 14000 milliseconds (14 seconds) to compare 2 strings of ~= 20 megabytes each!)
I decided to write the same function for JavaScript (almost a clone), and I was expecting it to be 10x to 20x slower than "Is()" function from AHK!
Guess what, "Is()" function from JavaScript takes only 741 milliseconds (less than 1 second) to compare 2 strings of ~= 20 megabytes each!
Wow, what'a surprise! It would suggest that, even JavaScript, is almost 19x faster than AHK?
[OBS]: I searched google and found out that most people agrees that JavaScript in fact compiles the whole script and then execute the machine\byte code?
Anyway, "Is()" function for JavaScript:
Code: Select all
<!DOCTYPE html>
<script>
x = "A";
for (i = 0; i < 20100100; i++) {x += "a";};
y = x;
x += "A";
y += "B";
Start_Time = new Date().getTime();
if (x == y)
{alert("yes (" + (new Date().getTime() - Start_Time) + " milliseconds)");}
else
{alert("no (" + (new Date().getTime() - Start_Time) + " milliseconds)");}
alert(Is(x, "=", y));
function Is(String1, Operator, String2) { //_________________________
var Char_1; var Char_2; var Index = 0; //"var" statement makes variables "local" inside functions
var Start_Time = new Date().getTime();
for (;;) { //Infinite loop
Index++;
Char_1 = String1.substring(Index - 1, Index);
Char_2 = String2.substring(Index - 1, Index);
if (Char_1 == Char_2)
{
if (Char_1 == "" && Char_2 == "") {return "yes (" + (new Date().getTime() - Start_Time) + " milliseconds)"};
}
else
{
return ""
+ "no (" + (new Date().getTime() - Start_Time) + " milliseconds)" + "\n"
+ "\n"
+ "Difference found at string position " + Index + "\n"
+ "\n"
+ "(" + Char_1 + ") != (" + Char_2 + ")\n\n\n"
};
};
};
</Script>