Language Speed Test

Apr 29, 2016
Language Speed Test
  • 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#
    Code (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)
    Code (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)
    Code (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)
    Code (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)
    Code (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 (Lua):
    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.