I would be shocked if there was any measurable difference, because the way Lua is designed allows it to do the check for each kind of object in basically the same way.
Measuring empirically, I got that == on each type takes between 0.1 and 0.2 microseconds on my computer (and all the types takes the same time to compare -- each varying in the same window).
Lua 5.1 (the version that Roblox uses) does not distinguish between integers and fractional numbers. They are all stored as 64 bit floating point numbers.
Here is the implementation of equality in Lua:
https://www.lua.org/source/5.1/lobject.c.html#luaO_rawequalObj
First, it checks if the types differ. The cost of doing this would be the same in all cases, because ttype just reads the same single word from the values.
Next, it chooses the right type. Doing this should be basically instant through cleverness in compiling C (and approximately uniform for all the types).
For numbers, the values are compared with C's == on floats. This will be essentially a single machine instruction, and one of the fastest.
For strings and tables, their addresses are compared (with C's pointer ==). This will be a single machine instruction, and basically the same speed as floating point. This is different from C++!
String comparison
In some languages, strings are compared by marching through the characters in them to see if they are different.
Lua does not do this, because it does string interning. This means that two strings that have the same content are stored in the same place. This means that == is as simple as determining if the place is the same -- which is just comparing two addresses (numbers).
In order to do this, every time that you create a string, Lua must walk over the string to figure out if you already have it! This unfortunately means that a .. b cannot be done in better that linear time and that a:sub(1, -2) requires copying the entire substring. Most of the time, we expect these operations to take that much time anyway, so we don't notice that Lua is doing this thing so that == becomes fast!
Optimization
Even so, you probably don't need to care about this. Almost surely, less than a fraction of a percent of your program's runtime is spent comparing objects for equality. So even if you make these comparisons 1000x faster, your program's overall speed can't improve by more than a fraction of a percent!
See here on the devforum for a longer post I've made on this.
2 comments
I'm sorry but before posting this I've already have a long research on the wiki. As it works that the rate slightly changes in real numbers as 1/s and 1.00001/s so it's really hard to recognize the differences between the two values
Ah, I see. I can’t really think of anything that can help you now. Sorry. :I