Language Speed Test

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,093
4,790
113
At your house.
github.com
It was about time to do the same test as I did here but for multiple languages.

https://forum.pluton.team/wiki/python-performance-boosting-in-for-cycles/

Basically I'm putting calculation pressure on the languages in a for cycle.
Everything besides C# runs on an interpreter (Normal language engines might be doing It faster or even slower.)

Here Are the results:


C#

C#:
var time = Util.GetUtil().TimeEpoch;
for (int i = 0; i < 750000; i++)
{
var num = Math.Sqrt(i);
}
Logger.LogWarning("Time taken: " + (time - Util.GetUtil().TimeEpoch));
Time taken: -0.00200009346008301 (Time is negative. Nice, nice xD. It was obvious that C# would win. But negative, lol)

JavaScript (Jint v1, Magma)

JavaScript:
function On_PluginInit() {
var s = Util.TimeEpoch;
for (var i = 0; i < 750000; i++) {
var ftc = Math.sqrt(i);
}
Plugin.Log("Test", "Time taken: " + (Util.TimeEpoch - s));
}
Time taken: 7.76144361495972 <- This is REALLY slow. Either the interpreter engine is written badly, or JS is really bad at calculations

JavaScript (Jint v2, Jint)

JavaScript:
function On_PluginInit() {
var s = Util.TimeEpoch;
for (var i = 0; i < 750000; i++) {
var ftc = Math.sqrt(i);
}
Plugin.Log("Test", "Time taken: " + (Util.TimeEpoch - s));
}
Time taken: 6.985399484634399 <- This is also slow.

Python (IronPython)

Python:
def On_PluginInit(self):
s = Util.TimeEpoch
for i in xrange(750000):
fct = i**.5
Plugin.Log("Test", "Time taken: " + str(Util.TimeEpoch - s))
Time taken: 0.151000976563 (Can be even less using the caching feature in python, described at the pluton forum, however this is obvious, they say Python rocks in maths)

Python Using the Caching Feature (IronPython)
Python:
def On_PluginInit(self, arg=math.sqrt):
s = Util.TimeEpoch
for i in xrange(750000):
fct = arg(i)
Plugin.Log("Test", "Time taken: " + str(Util.TimeEpoch - s))
Time taken: 0.106006145477

Lua (MoonSharp)
Code:
function On_PluginInit()
local s = Util.TimeEpoch
for i = 0, 750000, 1 do
local sq = math.sqrt(i)
end
Plugin:Log("Test", "Time taken: " .. (Util.TimeEpoch - s))
end
Time taken: 1.2960741519928 <- I was surprised that Lua is faster than JS V2, in real action, I doubt It would be. Maybe the interpreter (MoonSharp) is written really good.


Current Engine Speed Statistic:
C# > Python > Lua > Jint V2 > Jint V1 (Magma)

A really surprising end.

Summary:

Using slow methods in Rust causes the server to lagg. Since the method is running on the first thread, and Rust doesn't support multi threading, just sub threading, reading a big file, doing hard stuffs with slower engines can cause laggs like that. Ensure that you either do something threaded, or your code is fast enough.
 

MasterPeace

Retired Staff
Retired Staff
Feb 2, 2015
269
69
28
45
Poland
Yes. For Javascript it's not good option. Unity allows JS but we have no option to make something with it. Adding additional engines/libraries just to use JS is just bad idea, what your test show perfectly.

Python may be fast, it's gaining popularity from year to year (and I don't know why, what is best to do with it, why so big money is involved). Java is gaining popularity too, but we all know why - it's for everything, from pc to cars.
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,093
4,790
113
At your house.
github.com
Yes. For Javascript it's not good option. Unity allows JS but we have no option to make something with it. Adding additional engines/libraries just to use JS is just bad idea, what your test show perfectly.

Python may be fast, it's gaining popularity from year to year (and I don't know why, what is best to do with it, why so big money is involved). Java is gaining popularity too, but we all know why - it's for everything, from pc to cars.
It was my first language. I'm glad they are working on It and making It compatible.

Java is a nice language too, but the programming with It is kinda awful. HashMaps are Dictionaries, but you can't do Dict[x] with It, and many other easy syntax stuffs are missing. Java was my second language, and I used to be a Bukkit dev for MC.

Kinda miss It because of the money, but yes. It's everywhere. I wonder that Python with the big background and C# being open source now will take place of It in the future. But there are many companys that use java.

The thought though:

Fougerite/Pluton uses INTERPRETERS to ensure the biggest support and speed as much as It's possible.
There is the other way, where you NATIVELY implement a language Py/Js/Lua, such as the Oxide team does It. (But they only do It at lua, I'm sure MoonSharp is faster, since C# does the job in the background instead of native lua craps) If you check out the Pluton test or Fougerite test, Oxide's IronPython is a lot more slower. @hunternope3 confirmed that the C# stuffs are also slower. The reason is the background coding and nothing else.

~~ I added C#