Apt, Apache, and Lua

Not_OlesNot_Oles Hosting ProviderContent Writer
edited July 3 in Help

Today I tried upgrading my server which is running Debian unstable. I noticed that apache2 was held back. Here are some notes and a few questions at the end. Any help and comments will be greatly appreciated. Thanks!

Apt and Apache

root@lol ~ # apt-get update
Get:1 http://deb.debian.org/debian unstable InRelease [198 kB]
Get:2 http://deb.debian.org/debian unstable/main Sources [10.6 MB]
Get:3 http://deb.debian.org/debian unstable/main amd64 Packages [9,944 kB]
Get:4 http://deb.debian.org/debian unstable/main Translation-en [7,230 kB]
Fetched 28.0 MB in 2s (16.2 MB/s)                               
Reading package lists... Done
root@lol ~ # apt-get upgrade
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
The following packages have been kept back:
  apache2 apache2-bin apache2-data apache2-utils
0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.
root@lol ~ #

I wondered why apache2 was held back. I took a quick look at man apt-get and then tried to investigate with the --dry-run flag.

root@lol ~ # man apt-get
root@lol ~ # apt-get full-upgrade --dry-run
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
The following package was automatically installed and is no longer required:
  liblua5.3-0
Use 'apt autoremove' to remove it.
The following NEW packages will be installed:
  liblua5.4-0
The following packages will be upgraded:
  apache2 apache2-bin apache2-data apache2-utils
4 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Inst liblua5.4-0 (5.4.6-3+b1 Debian:unstable [amd64])
Inst apache2 [2.4.59-2] (2.4.60-1 Debian:unstable [amd64]) []
Inst apache2-bin [2.4.59-2] (2.4.60-1 Debian:unstable [amd64]) []
Inst apache2-data [2.4.59-2] (2.4.60-1 Debian:unstable [all]) []
Inst apache2-utils [2.4.59-2] (2.4.60-1 Debian:unstable [amd64])
Conf liblua5.4-0 (5.4.6-3+b1 Debian:unstable [amd64])
Conf apache2 (2.4.60-1 Debian:unstable [amd64])
Conf apache2-bin (2.4.60-1 Debian:unstable [amd64])
Conf apache2-data (2.4.60-1 Debian:unstable [all])
Conf apache2-utils (2.4.60-1 Debian:unstable [amd64])
root@lol ~ # 

Lua and Apache

Looks like

  • liblua5.3.0 had been installed,
  • the apache upgrade wanted liblua5.4.0, and that
  • apt was being careful by not auto-removing liblua5.3.0, which might have been in use.

Lua? Why Lua? I didn't remember installing liblua. I had heard that Lua was a computer language, but I didn't know about Lua.

The first result of a Google search for "liblua apache" was a link to an article, Lua for Apache, at admin-magazine.com. The article didn't seem to have a date, which always is a big red flag for me, but I decided to take a quick look. I was surprised that the article seemed well written.

I noticed that the article listing on Admin-magazine's home page had dates. So I searched in their search box for articles containing the word "lua." The second result was the article I wanted, Lua for Apache. The listing contained the date "10.07.2012."

The article explains that Lua is a scripting language developed in 1993 with these prominent features:

  • small, fast interpreter,
  • C interface,
  • imperative and functional,
  • "rudimentary" support for object-oriented programming, and
  • "minimal syntax."

The article says that the minimal syntax "makes Lua programs more cryptic than their PHP counterparts."

According to the article, there have been several implementations of Lua scripting for Apache. Several implementations are listed in the article. One of these, mod_wombat, by Brian McCallister, in 2006, has become [had become by 2012?] the mod_lua in the Apache mod family along with mod_perl and mod_php.

The article continues with

  • how to compile Apache with Lua enabled,
  • Apache configuration [again from 2012?] for Lua,
  • a Lua Hello world example,
  • an example form for first and last name, and
  • a discussion of hooks.

Questions

It looks like my Apt and apt-get options include

  • apt autoremove and then apt-get upgrade, and
  • apt-get full-upgrade.

Do I understand right that the former will leave liblua marked as autoinstalled, but that the latter will mark liblua as manually installed?

Does anybody here use Lua? Does anybody here use Lua with Apache? If yes, what particular feature of Lua appeals to you for your project?

New Apt Terminal Colors

By the way, Apt in Debian unstable has cool new terminal output colors! The new Apt colors look really great! It's fun to watch the Apt output!

Wish

Speaking of terminal colors, is anybody here using Wish?

I hope everyone gets the servers they want!

Tagged:

Comments

  • Debian's Changelog for apache2 has:

    Bump liblua from liblua5.3-dev to liblua5.4-dev (Closes: #1071701)

    So I think you'll have to do apt-get full-upgrade followed by apt-get autoremove (I don't think apt-get upgrade ever installs new packages)

    I am not using lua with apache, but have used it for some scripting (have written a lua scripting interface for clang and added lua scripting to exim4)

    Thanked by (1)Not_Oles
  • @Not_Oles said: It looks like my Apt and apt-get options include

    apt autoremove and then apt-get upgrade, and
    apt-get full-upgrade.

    What does the output of 'apt autoremove' show? I wouldn't think it would remove liblua5.3-0 because you still have a dependency on it because of your current version of apache2, right? autoremove will only remove dependencies if they are no longer required by another package, therefore the upgrade would still hold apache2 because liblua5.3-0 is still installed.

    apt full-upgrade will handle changes in dependencies by installing new packages and removing old ones, if needed - this will be your best option to upgrade apache2 as it will install liblua5.4-0 and remove liblua5.3-0 if no longer needed by any other packages.

    A apt full-upgrade would also mark the liblua5.4-0 package as automatically installed as it was installed for a dependency against apache2.

    I've used Lua lightly in the past, nothing extreme and never used it with Apache either.

    Thanked by (1)Not_Oles

    SharedGrid | Fast, secure, and reliable UK, USA and Singapore web, reseller and VPS Hosting
    Litespeed, Redis Cache, NVMe Drives, Daily Backups, 24x7 Support, Wordpress Optimised.

  • edited July 3

    As you've searched, Lua is a scripting language designed for extending applications.

    For example, I wrote a trivial Lua script for FCEUX (a NES/Famicom emulator) to monitor and modify the weapons used in game Super Contra .

    FCEUX can't hard code the cheat code in source code for every game, but when combined with Lua, it provides an interpreter which is able to read player's script to cheat, thus extending the functions of the software.

    As for apache's case, I guess it may be the same.

    If someone likes this nostalgic Super Contra, you may try this Lua code:

    while (true) do
        local addr_gun_type_1p = 0x00b8;
        local addr_gun_type_2p = 0x00b9;
        local fc = emu.framecount();
        local gun_type = memory.readbyteunsigned(addr_gun_type_1p);
    
        if (fc % 5 == 0) then
            if (gun_type == 130) then
                memory.writebyte(addr_gun_type_1p, 133);
                memory.writebyte(addr_gun_type_2p, 130);
            elseif (gun_type == 133) then
                memory.writebyte(addr_gun_type_1p, 128);
                memory.writebyte(addr_gun_type_2p, 133);
            else
                memory.writebyte(addr_gun_type_1p, 130);
                memory.writebyte(addr_gun_type_2p, 128);
            end;
        end;
    
    --    gui.text(15,15, tostring(gun_type));
    
        FCEU.frameadvance();
    end;
    
    Thanked by (1)Not_Oles

    MicroLXC is lovable. Uptime of C1V

  • Not_OlesNot_Oles Hosting ProviderContent Writer

    @SharedGrid said: What does the output of 'apt autoremove' show?

    root@lol ~ # date; apt autoremove
    Wed Jul  3 07:18:30 PM UTC 2024
    Summary:                        
      Upgrading: 0, Installing: 0, Removing: 0, Not Upgrading: 4
    root@lol ~ # 
    

    Looks like a couple more updates were added since yesterday.

    root@lol ~ # date; apt update
    Wed Jul  3 07:22:25 PM UTC 2024
    Get:1 http://deb.debian.org/debian unstable InRelease [198 kB]
    Get:2 http://deb.debian.org/debian unstable/main Sources [10.6 MB]
    Get:3 http://deb.debian.org/debian unstable/main amd64 Packages [9,945 kB]
    Get:4 http://deb.debian.org/debian unstable/main Translation-en [7,229 kB]
    Fetched 28.0 MB in 2s (16.3 MB/s)                               
    11 packages can be upgraded. Run 'apt list --upgradable' to see them.
    root@lol ~ # apt list --upgradeable
    apache2-bin/unstable 2.4.60-1 amd64 [upgradable from: 2.4.59-2]
    apache2-data/unstable 2.4.60-1 all [upgradable from: 2.4.59-2]
    apache2-utils/unstable 2.4.60-1 amd64 [upgradable from: 2.4.59-2]
    apache2/unstable 2.4.60-1 amd64 [upgradable from: 2.4.59-2]
    apt-utils/unstable 2.9.6 amd64 [upgradable from: 2.9.5]
    apt/unstable 2.9.6 amd64 [upgradable from: 2.9.5]
    curl/unstable 8.8.0-2 amd64 [upgradable from: 8.8.0-1]
    libapt-pkg6.0t64/unstable 2.9.6 amd64 [upgradable from: 2.9.5]
    libcurl3t64-gnutls/unstable 8.8.0-2 amd64 [upgradable from: 8.8.0-1]
    libcurl4t64/unstable 8.8.0-2 amd64 [upgradable from: 8.8.0-1]
    libnbd0/unstable 1.20.2-1 amd64 [upgradable from: 1.20.1-1+b1]
    root@lol ~ # apt full-upgrade
    The following package was automatically installed and is no longer required:
      liblua5.3-0
    Use 'apt autoremove' to remove it. 
    
    Upgrading:
      apache2       apache2-utils  curl                libcurl4t64
      apache2-bin   apt            libapt-pkg6.0t64    libnbd0
      apache2-data  apt-utils      libcurl3t64-gnutls
    
    Installing dependencies:
      liblua5.4-0  libnghttp3-9  libngtcp2-16  libngtcp2-crypto-gnutls8
    
    Summary:
      Upgrading: 11, Installing: 4, Removing: 0, Not Upgrading: 0
      Download size: 6,401 kB
      Space needed: 1,298 kB / 2,840 GB available
    
    Continue? [Y/n] 
    Get:1 http://deb.debian.org/debian unstable/main amd64 libapt-pkg6.0t64 amd64 2.9.6 [1,020 kB]
    Get:2 http://deb.debian.org/debian unstable/main amd64 apt amd64 2.9.6 [1,398 kB]
    Get:3 http://deb.debian.org/debian unstable/main amd64 apt-utils amd64 2.9.6 [328 kB]
    Get:4 http://deb.debian.org/debian unstable/main amd64 libnghttp3-9 amd64 1.3.0-2 [64.7 kB]
    Get:5 http://deb.debian.org/debian unstable/main amd64 libngtcp2-16 amd64 1.5.0-2 [126 kB]
    Get:6 http://deb.debian.org/debian unstable/main amd64 libngtcp2-crypto-gnutls8 amd64 1.5.0-2 [22.9 kB]
    Get:7 http://deb.debian.org/debian unstable/main amd64 libcurl3t64-gnutls amd64 8.8.0-2 [451 kB]
    Get:8 http://deb.debian.org/debian unstable/main amd64 curl amd64 8.8.0-2 [347 kB]
    Get:9 http://deb.debian.org/debian unstable/main amd64 libcurl4t64 amd64 8.8.0-2 [445 kB]
    Get:10 http://deb.debian.org/debian unstable/main amd64 liblua5.4-0 amd64 5.4.6-3+b1 [147 kB]
    Get:11 http://deb.debian.org/debian unstable/main amd64 apache2 amd64 2.4.60-1 [215 kB]
    Get:12 http://deb.debian.org/debian unstable/main amd64 apache2-bin amd64 2.4.60-1 [1,385 kB]
    Get:13 http://deb.debian.org/debian unstable/main amd64 apache2-data all 2.4.60-1 [160 kB]
    Get:14 http://deb.debian.org/debian unstable/main amd64 apache2-utils amd64 2.4.60-1 [209 kB]
    Get:15 http://deb.debian.org/debian unstable/main amd64 libnbd0 amd64 1.20.2-1 [83.1 kB]
    Fetched 6,401 kB in 0s (81.7 MB/s)  
    (Reading database ... 98291 files and directories currently installed.)
    Preparing to unpack .../libapt-pkg6.0t64_2.9.6_amd64.deb ...
    Unpacking libapt-pkg6.0t64:amd64 (2.9.6) over (2.9.5) ...
    Setting up libapt-pkg6.0t64:amd64 (2.9.6) ...
    (Reading database ... 98291 files and directories currently installed.)
    Preparing to unpack .../archives/apt_2.9.6_amd64.deb ...
    Unpacking apt (2.9.6) over (2.9.5) ...
    Setting up apt (2.9.6) ...
    (Reading database ... 98291 files and directories currently installed.)
    Preparing to unpack .../00-apt-utils_2.9.6_amd64.deb ...
    Unpacking apt-utils (2.9.6) over (2.9.5) ...
    Selecting previously unselected package libnghttp3-9:amd64.
    Preparing to unpack .../01-libnghttp3-9_1.3.0-2_amd64.deb ...
    Unpacking libnghttp3-9:amd64 (1.3.0-2) ...
    Selecting previously unselected package libngtcp2-16:amd64.
    Preparing to unpack .../02-libngtcp2-16_1.5.0-2_amd64.deb ...
    Unpacking libngtcp2-16:amd64 (1.5.0-2) ...
    Selecting previously unselected package libngtcp2-crypto-gnutls8:amd64.
    Preparing to unpack .../03-libngtcp2-crypto-gnutls8_1.5.0-2_amd64.deb ...
    Unpacking libngtcp2-crypto-gnutls8:amd64 (1.5.0-2) ...
    Preparing to unpack .../04-libcurl3t64-gnutls_8.8.0-2_amd64.deb ...
    Unpacking libcurl3t64-gnutls:amd64 (8.8.0-2) over (8.8.0-1) ...
    Preparing to unpack .../05-curl_8.8.0-2_amd64.deb ...
    Unpacking curl (8.8.0-2) over (8.8.0-1) ...
    Preparing to unpack .../06-libcurl4t64_8.8.0-2_amd64.deb ...
    Unpacking libcurl4t64:amd64 (8.8.0-2) over (8.8.0-1) ...
    Selecting previously unselected package liblua5.4-0:amd64.
    Preparing to unpack .../07-liblua5.4-0_5.4.6-3+b1_amd64.deb ...
    Unpacking liblua5.4-0:amd64 (5.4.6-3+b1) ...
    Preparing to unpack .../08-apache2_2.4.60-1_amd64.deb ...
    Unpacking apache2 (2.4.60-1) over (2.4.59-2) ...
    Preparing to unpack .../09-apache2-bin_2.4.60-1_amd64.deb ...
    Unpacking apache2-bin (2.4.60-1) over (2.4.59-2) ...
    Preparing to unpack .../10-apache2-data_2.4.60-1_all.deb ...
    Unpacking apache2-data (2.4.60-1) over (2.4.59-2) ...
    Preparing to unpack .../11-apache2-utils_2.4.60-1_amd64.deb ...
    Unpacking apache2-utils (2.4.60-1) over (2.4.59-2) ...
    Preparing to unpack .../12-libnbd0_1.20.2-1_amd64.deb ...
    Unpacking libnbd0 (1.20.2-1) over (1.20.1-1+b1) ...
    Setting up apt-utils (2.9.6) ...
    Setting up libcurl4t64:amd64 (8.8.0-2) ...
    Setting up libnbd0 (1.20.2-1) ...
    Setting up libnghttp3-9:amd64 (1.3.0-2) ...
    Setting up liblua5.4-0:amd64 (5.4.6-3+b1) ...
    Setting up libngtcp2-16:amd64 (1.5.0-2) ...
    Setting up apache2-data (2.4.60-1) ...
    Setting up libngtcp2-crypto-gnutls8:amd64 (1.5.0-2) ...
    Setting up apache2-utils (2.4.60-1) ...
    Setting up libcurl3t64-gnutls:amd64 (8.8.0-2) ...
    Setting up apache2-bin (2.4.60-1) ...
    Setting up curl (8.8.0-2) ...
    Setting up apache2 (2.4.60-1) ...
    apache-htcacheclean.service is a disabled or a static unit not running, not starting it.
    Processing triggers for ufw (0.36.2-6) ...
    Processing triggers for man-db (2.12.1-2) ...
    Processing triggers for libc-bin (2.38-13) ...
    root@lol ~ # apt autoremove
    REMOVING:                       
      liblua5.3-0
    
    Summary:
      Upgrading: 0, Installing: 0, Removing: 1, Not Upgrading: 0
      Freed space: 520 kB
    
    Continue? [Y/n] 
    (Reading database ... 98322 files and directories currently installed.)
    Removing liblua5.3-0:amd64 (5.3.6-2+b2) ...
    Processing triggers for libc-bin (2.38-13) ...
    root@lol ~ # 
    

    @SharedGrid said: A apt full-upgrade would also mark the liblua5.4-0 package as automatically installed

    Looks like you are exactly right.

    root@lol ~ # apt show liblua5.4-0
    Package: liblua5.4-0
    Version: 5.4.6-3+b1
    Priority: optional
    Section: libs
    Source: lua5.4 (5.4.6-3)
    Maintainer: Debian Lua Team <[email protected]>
    Installed-Size: 586 kB
    Depends: libc6 (>= 2.34), libstdc++6 (>= 4.1.1)
    Homepage: http://www.lua.org
    Tag: role::shared-lib
    Download-Size: 147 kB
    APT-Manual-Installed: no
    APT-Sources: http://deb.debian.org/debian unstable/main amd64 Packages
    Description: Shared library for the Lua interpreter version 5.4
     Lua is a powerful, light-weight programming language designed for extending
     applications.  The language engine is accessible as a library, having a C
     API which allows the application to exchange data with Lua programs and also
     to extend Lua with C functions.  Lua is also used as a general-purpose,
     stand-alone language through the simple command line interpreter provided.
     .
     This package contains runtime libraries.  You shouldn't need to install it
     explicitly.
    
    root@lol ~ # 
    

    I hope everyone gets the servers they want!

  • Not_OlesNot_Oles Hosting ProviderContent Writer

    @cmeerw said:
    Debian's Changelog for apache2 has:

    Bump liblua from liblua5.3-dev to liblua5.4-dev (Closes: #1071701)

    Thanks for the link to the changelog. I have to look at those changelogs!

    So I think you'll have to do apt-get full-upgrade followed by apt-get autoremove (I don't think apt-get upgrade ever installs new packages)

    Yup! See apt full-upgrade output just posted above.

    I am not using lua with apache, but have used it for some scripting (have written a lua scripting interface for clang and added lua scripting to exim4)

    May I please ask, did you pick Lua for speed in these two uses? Or, was there another advantage of Lua which was especially attractive in these two applications?

    Thanks for your reply here! Much appreciated! <3

    I hope everyone gets the servers they want!

  • Not_OlesNot_Oles Hosting ProviderContent Writer

    @entrailz mentioned on OGF that Cloudflare uses Lua. I didn't know that! I found https://blog.cloudflare.com/more-consistent-luajit-performance which is a really interesting blog post from December 2018 covering Lua performance testing at King's Collge London that was sponsored by Cloudflare. The post doesn't talk about why Cloudflare uses Lua and where Cloudflare uses Lua, but it sure seems clear that Cloudflare had been looking at Lua very carefully as of 2018. Fun to read!

    I hope everyone gets the servers they want!

  • @Not_Oles said: May I please ask, did you pick Lua for speed in these two uses? Or, was there another advantage of Lua which was especially attractive in these two applications?

    Mainly because Lua is very small (much smaller than something like Python) and easy to interface with C and/or C++ code (again, the Lua C API is a lot easier to work with than the Python API).

    Thanked by (1)Not_Oles
  • Not_OlesNot_Oles Hosting ProviderContent Writer

    Google Gemini wrote a program in response to my request to compare time taken to write "hello world" 10,000 times to /dev/null in C versus in Lua from C versus in Python from C. Here is the program, the compile command, and the result in case anybody might be interested. No claim that the program makes sense and no claim that the result is meaningful. :) But it definitely was fun messing with this program! :)

    root@lol ~/c-lua-python # cat hello_world_files.c # Version 5
    #include <stdio.h>
    #include <lua.h>
    #include <lauxlib.h>
    #include <lualib.h>
    #include <Python.h>
    #include <time.h>  
    
    #define NUM_ITERATIONS 10000 // Increased iterations
    
    // Function to measure execution time with an additional void pointer argument
    double measure_time(void (*func)(void *), void *arg) {
        clock_t start, end;
        double cpu_time_used;
    
        start = clock();
        func(arg); // Call the function with its argument
        end = clock();
        cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
        return cpu_time_used;
    }
    
    // Function to write "hello world" to /dev/null using C 
    void write_hello_c() {
        FILE *dev_null = fopen("/dev/null", "w");
        for (int i = 0; i < NUM_ITERATIONS; i++) {
            fprintf(dev_null, "hello world from C\n");
        }
        fclose(dev_null);
    }
    
    // Corrected Lua function
    void write_hello_lua(void *arg) {
        lua_State *L = (lua_State *)arg;  
        char lua_script[200];  // Increased size for the Lua script
        snprintf(lua_script, sizeof(lua_script), "for i = 1, %d do local devnull = io.open('/dev/null', 'w') devnull:write('hello world from Lua\\n') devnull:close() end", NUM_ITERATIONS);
    
        if (luaL_loadstring(L, lua_script) != LUA_OK) {
            fprintf(stderr, "Error: %s\n", lua_tostring(L, -1));
        }
    
        lua_pcall(L, 0, 0, 0);
    }
    
    // Function to write "hello world" to /dev/null using Python
    void write_hello_python() {
        PyRun_SimpleString(
            "import os\n" // Add import statement for os
            "for i in range(10000):\n"
            "    print('hello world from Python', file=open(os.devnull, 'w'))" 
        );
    }
    
    int main() {
        lua_State *L = luaL_newstate();
        luaL_openlibs(L);
    
        Py_Initialize();
    
        // Open /dev/null before timing
        FILE *dev_null = fopen("/dev/null", "w");
    
        double c_time = measure_time(write_hello_c, NULL); 
        double lua_time = measure_time(write_hello_lua, L);  
        double python_time = measure_time(write_hello_python, NULL); 
    
        // Close resources
        fclose(dev_null);
        lua_close(L);
        Py_Finalize();
    
        // Measure and print times
        printf("C average time: %f seconds\n", c_time);
        printf("Lua average time: %f seconds\n", lua_time);
        printf("Python average time: %f seconds\n", python_time);
    
        return 0;
    }
    root@lol ~/c-lua-python # 
    
    root@lol ~/c-lua-python # gcc -o hello_world_files hello_world_files.c -I/usr/include/python3.12 -L/usr/lib/python3.12 -lpython3.12 -I/usr/include/lua5.3 -llua5.3
    
    root@lol ~/c-lua-python # time ./hello_world_files 
    C average time: 0.000065 seconds
    Lua average time: 0.015810 seconds
    Python average time: 0.050548 seconds
    
    real    0m0.081s
    user    0m0.045s
    sys     0m0.037s
    root@lol ~/c-lua-python # date
    Thu Jul  4 02:22:26 AM UTC 2024
    root@lol ~/c-lua-python # 
    

    I hope everyone gets the servers they want!

  • Not_OlesNot_Oles Hosting ProviderContent Writer

    Gemini and I kept going through many more versions of this program, trying to modify it to use either with the regular Lua Interpreter or with LuaJIT. Finally we mutually decided to give up on the idea of combining Lua Interpreter and LuaJIT in the single program. Gemini wanted to simplify by writing two separate programs, one comparing C, Lua, and Python, and the other comparing C, LuaJIT, and Python. Here is the first of the two programs, the compile command, and the output.

    root@lol ~/c-luajit-python # cat -n hello_world_files_lua-9.0.c
         1  #include <stdio.h>
         2  #include <string.h>  // for strcmp, strlen
         3  #include <time.h>    // for clock, CLOCKS_PER_SEC
         4  #include <Python.h>  // for Python C API
         5
         6  #include <lua5.3/lua.h>
         7  #include <lua5.3/lauxlib.h>
         8  #include <lua5.3/lualib.h>   
         9
        10  #define NUM_ITERATIONS 10000 // Increased iterations
        11
        12  // Function prototypes (forward declarations)
        13  void write_hello_c();
        14  void write_hello_python();
        15
        16  // Function to measure execution time with an additional void pointer argument
        17  double measure_time(void (*func)(void *), void *arg) {
        18      clock_t start, end;
        19      double cpu_time_used;
        20
        21      start = clock();
        22      func(arg); // Call the function with its argument
        23      end = clock();
        24      cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
        25      return cpu_time_used;
        26  }
        27
        28  // Function to write "hello world" to /dev/null using C 
        29  void write_hello_c() {
        30      FILE *dev_null = fopen("/dev/null", "w");
        31      for (int i = 0; i < NUM_ITERATIONS; i++) {
        32          fprintf(dev_null, "hello world from C\n");
        33      }
        34      fclose(dev_null);
        35  }
        36
        37
        38  // Function to write "hello world" to /dev/null using Lua
        39  void write_hello_lua() {
        40      lua_State *L = luaL_newstate(); 
        41      luaL_openlibs(L);               
        42      
        43      // Open devnull outside of the loop
        44      luaL_loadstring(L, "devnull = io.open('/dev/null', 'w')");  // Open /dev/null before the loop
        45      lua_pcall(L, 0, 0, 0);
        46
        47      char lua_script[200];
        48      snprintf(lua_script, sizeof(lua_script), "for i = 1, %d do devnull:write('hello world from Lua\\n') end", NUM_ITERATIONS);
        49     
        50      if (luaL_loadbuffer(L, lua_script, strlen(lua_script), "hello_world_lua") != LUA_OK) {
        51          fprintf(stderr, "Error: %s\n", lua_tostring(L, -1));
        52      }
        53
        54      lua_pcall(L, 0, 0, 0); // Execute the loaded Lua script
        55
        56      // Close devnull after the loop
        57      luaL_loadstring(L, "devnull:close()"); // Close /dev/null after the loop
        58      lua_pcall(L, 0, 0, 0);
        59
        60      lua_close(L);
        61  }
        62
        63  // Function to write "hello world" to /dev/null using Python
        64  void write_hello_python() {
        65      PyRun_SimpleString(
        66          "import os\n" // Add import statement for os
        67          "for i in range(10000):\n"
        68          "    print('hello world from Python', file=open(os.devnull, 'w'))" 
        69      );
        70  }
        71
        72  int main(int argc, char *argv[]) {
        73      (void)argc; // unused parameter
        74      (void)argv; // unused parameter
        75
        76      Py_Initialize();
        77      
        78      double c_time = measure_time(write_hello_c, NULL); 
        79      double lua_time = measure_time(write_hello_lua, NULL); 
        80      double python_time = measure_time(write_hello_python, NULL); 
        81      
        82      Py_Finalize();
        83
        84      // Measure and print times and calculate ratios
        85      printf("C average time: %f seconds\n", c_time);
        86      printf("Lua average time: %f seconds\n", lua_time); 
        87      printf("Python average time: %f seconds\n", python_time);
        88
        89      if (c_time == 0 || lua_time == 0) {
        90          printf("Division by zero would occur, so no comparison is made.\n");
        91      } else {
        92          printf("C is %.2f times faster than Lua\n", lua_time / c_time);
        93          printf("Lua is %.2f times faster than Python\n", python_time / lua_time);
        94      }
        95
        96      return 0;
        97  }
        98
    root@lol ~/c-luajit-python # gcc -o hello_world_files_lua hello_world_files_lua-9.0.c -I/usr/inclu
    de/python3.12 -L/usr/lib/python3.12 -lpython3.12 -llua5.3
    root@lol ~/c-luajit-python # ./hello_world_files_lua 
    C average time: 0.000112 seconds
    Lua average time: 0.000797 seconds
    Python average time: 0.058817 seconds
    C is 7.12 times faster than Lua
    Lua is 73.80 times faster than Python
    root@lol ~/c-luajit-python # 
    

    I hope everyone gets the servers they want!

  • Not_OlesNot_Oles Hosting ProviderContent Writer

    Here is the second version or the program using LuaJIT. with the compile command and the output.

    root@lol ~/c-luajit-python # cat -n hello_world_files_luajit-9.1.c
         1  #include <stdio.h>
         2  #include <string.h>  // for strlen
         3  #include <time.h>    // for clock, CLOCKS_PER_SEC
         4  #include <Python.h>  // for Python C API
         5
         6  #include <luajit-2.1/lua.h>   // Include LuaJIT headers
         7  #include <luajit-2.1/lauxlib.h>
         8  #include <luajit-2.1/lualib.h>
         9
        10  #define NUM_ITERATIONS 10000 // Number of iterations for each language
        11
        12  // Function to measure execution time with an additional void pointer argument
        13  double measure_time(void (*func)(void *), void *arg) {
        14      clock_t start, end;
        15      double cpu_time_used;
        16
        17      start = clock();
        18      func(arg); // Call the function with its argument
        19      end = clock();
        20      cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
        21      return cpu_time_used;
        22  }
        23
        24  // Function to write "hello world" to /dev/null using C 
        25  void write_hello_c() {
        26      FILE *dev_null = fopen("/dev/null", "w");
        27      for (int i = 0; i < NUM_ITERATIONS; i++) {
        28          fprintf(dev_null, "hello world from C\n");
        29      }
        30      fclose(dev_null);
        31  }
        32
        33  // Function to write "hello world" to /dev/null using LuaJIT
        34  void write_hello_lua() {
        35      lua_State *L = luaL_newstate(); 
        36      luaL_openlibs(L);               
        37
        38      // Open devnull outside of the loop
        39      luaL_loadstring(L, "devnull = io.open('/dev/null', 'w')");  
        40      lua_pcall(L, 0, 0, 0);
        41
        42      char lua_script[200];
        43      snprintf(lua_script, sizeof(lua_script), "for i = 1, %d do devnull:write('hello world from LuaJIT\\n') end", NUM_ITERATIONS);
        44     
        45      if (luaL_loadbuffer(L, lua_script, strlen(lua_script), "hello_world_lua") != LUA_OK) {
        46          fprintf(stderr, "Error: %s\n", lua_tostring(L, -1));
        47      }
        48
        49      lua_pcall(L, 0, 0, 0);
        50
        51      // Close devnull after the loop
        52      luaL_loadstring(L, "devnull:close()"); 
        53      lua_pcall(L, 0, 0, 0);
        54
        55      lua_close(L);
        56  }
        57
        58  // Function to write "hello world" to /dev/null using Python
        59  void write_hello_python() {
        60      PyRun_SimpleString(
        61          "import os\n"
        62          "for i in range(10000):\n"
        63          "    print('hello world from Python', file=open(os.devnull, 'w'))" 
        64      );
        65  }
        66
        67  int main() {
        68
        69      Py_Initialize();
        70      
        71      double c_time = measure_time(write_hello_c, NULL); 
        72      double lua_time = measure_time(write_hello_lua, NULL); 
        73      double python_time = measure_time(write_hello_python, NULL); 
        74      
        75      Py_Finalize();
        76
        77      // Measure and print times and calculate ratios
        78      printf("C average time: %f seconds\n", c_time);
        79      printf("LuaJIT average time: %f seconds\n", lua_time); 
        80      printf("Python average time: %f seconds\n", python_time);
        81
        82      if (c_time == 0 || lua_time == 0) {
        83          printf("Division by zero would occur, so no comparison is made.\n");
        84      } else {
        85          printf("C is %.2f times faster than LuaJIT\n", lua_time / c_time);
        86          printf("LuaJIT is %.2f times faster than Python\n", python_time / lua_time);
        87      }
        88
        89      return 0;
        90  }
    root@lol ~/c-luajit-python # gcc -o hello_world_files_luajit hello_world_files_luajit-9.1.c -I/usr/include/python3.12 -L/usr/lib/python3.12 -lpython3.12 -lluajit-5.1
    root@lol ~/c-luajit-python # ./hello_world_files_luajit 
    C average time: 0.000072 seconds
    LuaJIT average time: 0.000186 seconds
    Python average time: 0.053127 seconds
    C is 2.58 times faster than LuaJIT
    LuaJIT is 285.63 times faster than Python
    root@lol ~/c-luajit-python # 
    

    I hope everyone gets the servers they want!

  • edited July 8

    I was actually wondering why Lua time went from

    Lua average time: 0.015810 seconds

    to

    Lua average time: 0.000797 seconds

    as that's a huge difference.

    Well, in the first version you are opening '/dev/null' on each iteration, while in the next versions you open '/dev/null' only once.

    And then looking at the Python code, you are also always opening '/dev/null' on each iteration. To get a slightly fairer comparison, the Python code to be executed should really be:

    PyRun_SimpleString(
        "import os\n"
        "with open(os.devnull, 'w') as devnull:\n"
        "    for i in range(10000):\n"
        "        print('hello world from Python', file=devnull)"
    );
    

    and then I get something like:

    LuaJIT is 22.65 times faster than Python
    Lua is 6.86 times faster than Python

    which is a bit more reasonable.

    Thanked by (1)Not_Oles
  • Interesting. Took the liberty to copy and extend the lua (not the jit) script to measure the same with pypy -- crude, ran it on a new function with system(pypy a.py) on my notebook (not a vm).

    sandbox@e14:~/x$ cat a.py
    from __future__ import print_function
    import os
    for i in range(10000):
      print('hello world from Python', file=open(os.devnull, 'w'))
    sandbox@e14:~/x$ ulimit -n 10240
    sandbox@e14:~/x$ gcc a.c -o a -I/usr/include/python3.10 -L/usr/lib/python3.10 -lpython3.10 -I/usr/include/lua5.4 -llua5.4
    sandbox@e14:~/x$ ./a
    C average time: 0.000192 seconds
    Lua average time: 0.001316 seconds
    Python average time: 0.189144 seconds
    PyPy average time: 0.000729 seconds
    C is 6.85 times faster than Lua
    C is 985.12 times faster than Python
    C is 3.80 times faster than PyPy
    Lua is 143.73 times faster than Python
    PyPy is 259.46 times faster than Python
    

    Cool.

    Thanked by (1)Not_Oles
  • Not_OlesNot_Oles Hosting ProviderContent Writer

    @cmeerw

    Thanks for catching this mistake! You made my day!!

    Please let me work through what you said to make sure that I understand.

    @cmeerw said: Well, in the first version you are opening '/dev/null' on each iteration, while in the next versions you open '/dev/null' only once.

    This change you are decribing starts with the write_hello_lua() function in Version 5 (the first version posted above)

    // Corrected Lua function
    void write_hello_lua(void *arg) {
        lua_State *L = (lua_State *)arg;  
        char lua_script[200];  // Increased size for the Lua script
        snprintf(lua_script, sizeof(lua_script), "for i = 1, %d do local devnull = io.open('/dev/null', 'w') devnull:write('hello world from Lua\\n') devnull:close() end", NUM_ITERATIONS);
    
        if (luaL_loadstring(L, lua_script) != LUA_OK) {
            fprintf(stderr, "Error: %s\n", lua_tostring(L, -1));
        }
    
        lua_pcall(L, 0, 0, 0);
    }
    

    where it can be seen that the line

        snprintf(lua_script, sizeof(lua_script), "for i = 1, %d do local devnull = io.open('/dev/null', 'w') devnull:write('hello world from Lua\\n') devnull:close() end", NUM_ITERATIONS);
    

    opens /dev/null for each write.

    By contrast, the second and third versions posted above are hello_world_files_lua-9.0.c (the second version posted above)

        38  // Function to write "hello world" to /dev/null using Lua
        39  void write_hello_lua() {
        40      lua_State *L = luaL_newstate(); 
        41      luaL_openlibs(L);               
        42      
        43      // Open devnull outside of the loop
        44      luaL_loadstring(L, "devnull = io.open('/dev/null', 'w')");  // Open /dev/null before the loop
        45      lua_pcall(L, 0, 0, 0);
        46
        47      char lua_script[200];
        48      snprintf(lua_script, sizeof(lua_script), "for i = 1, %d do devnull:write('hello world from Lua\\n') end", NUM_ITERATIONS);
        49     
        50      if (luaL_loadbuffer(L, lua_script, strlen(lua_script), "hello_world_lua") != LUA_OK) {
        51          fprintf(stderr, "Error: %s\n", lua_tostring(L, -1));
        52      }
        53
        54      lua_pcall(L, 0, 0, 0); // Execute the loaded Lua script
        55
        56      // Close devnull after the loop
        57      luaL_loadstring(L, "devnull:close()"); // Close /dev/null after the loop
        58      lua_pcall(L, 0, 0, 0);
        59
        60      lua_close(L);
        61  }
    

    and hello_world_files_luajit-9.1.c. (the third version posted above)

        33  // Function to write "hello world" to /dev/null using LuaJIT
        34  void write_hello_lua() {
        35      lua_State *L = luaL_newstate(); 
        36      luaL_openlibs(L);               
        37
        38      // Open devnull outside of the loop
        39      luaL_loadstring(L, "devnull = io.open('/dev/null', 'w')");  
        40      lua_pcall(L, 0, 0, 0);
        41
        42      char lua_script[200];
        43      snprintf(lua_script, sizeof(lua_script), "for i = 1, %d do devnull:write('hello world from LuaJIT\\n') end", NUM_ITERATIONS);
        44     
        45      if (luaL_loadbuffer(L, lua_script, strlen(lua_script), "hello_world_lua") != LUA_OK) {
        46          fprintf(stderr, "Error: %s\n", lua_tostring(L, -1));
        47      }
        48
        49      lua_pcall(L, 0, 0, 0);
        50
        51      // Close devnull after the loop
        52      luaL_loadstring(L, "devnull:close()"); 
        53      lua_pcall(L, 0, 0, 0);
        54
        55      lua_close(L);
        56  }
    

    In the second and third versions posted above, the following lines open /dev/null only once, ahead of the write loop.

        43      // Open devnull outside of the loop
        44      luaL_loadstring(L, "devnull = io.open('/dev/null', 'w')");  // Open /dev/null before the loop
    
        38      // Open devnull outside of the loop
        39      luaL_loadstring(L, "devnull = io.open('/dev/null', 'w')");  
    

    @cmeerw said: And then looking at the Python code, you are also always opening '/dev/null' on each iteration.

    Yes! In Version 5,

    // Function to write "hello world" to /dev/null using Python
    void write_hello_python() {
        PyRun_SimpleString(
            "import os\n" // Add import statement for os
            "for i in range(10000):\n"
            "    print('hello world from Python', file=open(os.devnull, 'w'))" 
        );
    }
    

    and in hello_world_files_lua-9.0.c,

        63  // Function to write "hello world" to /dev/null using Python
        64  void write_hello_python() {
        65      PyRun_SimpleString(
        66          "import os\n" // Add import statement for os
        67          "for i in range(10000):\n"
        68          "    print('hello world from Python', file=open(os.devnull, 'w'))" 
        69      );
        70  }
    

    and in hello_world_files_luajit-9.1.c,

        58  // Function to write "hello world" to /dev/null using Python
        59  void write_hello_python() {
        60      PyRun_SimpleString(
        61          "import os\n"
        62          "for i in range(10000):\n"
        63          "    print('hello world from Python', file=open(os.devnull, 'w'))" 
        64      );
        65  }
    

    the identical line

    " print('hello world from Python', file=open(os.devnull, 'w'))"

    always opens /dev/null for each write.

    It's unfair to make Python open /dev/null 10,000 times when Lua and LuaJIT only have to open /dev/null once!

    @cmeerw said: the Python code to be executed should really be:

    PyRun_SimpleString(
       "import os\n"
       "with open(os.devnull, 'w') as devnull:\n"
       "    for i in range(10000):\n"
       "        print('hello world from Python', file=devnull)"
    );
    

    I will change the Python portion of the code as you recommend, recompile, and post the revised results.

    Thanks again for taking the time to point out the mistake in the code and for providing the correction! I really appreciate it! <3

    I hope everyone gets the servers they want!

  • Not_OlesNot_Oles Hosting ProviderContent Writer
    root@lol ~/c-luajit-python # cat -n hello_world_files_lua-10.0.c 
         1  #include <stdio.h>
         2  #include <string.h>  // for strcmp, strlen
         3  #include <time.h>    // for clock, CLOCKS_PER_SEC
         4  #include <Python.h>  // for Python C API
         5
         6  #include <lua5.3/lua.h>
         7  #include <lua5.3/lauxlib.h>
         8  #include <lua5.3/lualib.h>   
         9
        10  #define NUM_ITERATIONS 10000 // Increased iterations
        11
        12  // Function prototypes (forward declarations)
        13  void write_hello_c();
        14  void write_hello_python();
        15
        16  // Function to measure execution time with an additional void pointer argument
        17  double measure_time(void (*func)(void *), void *arg) {
        18      clock_t start, end;
        19      double cpu_time_used;
        20
        21      start = clock();
        22      func(arg); // Call the function with its argument
        23      end = clock();
        24      cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
        25      return cpu_time_used;
        26  }
        27
        28  // Function to write "hello world" to /dev/null using C 
        29  void write_hello_c() {
        30      FILE *dev_null = fopen("/dev/null", "w");
        31      for (int i = 0; i < NUM_ITERATIONS; i++) {
        32          fprintf(dev_null, "hello world from C\n");
        33      }
        34      fclose(dev_null);
        35  }
        36
        37
        38  // Function to write "hello world" to /dev/null using Lua
        39  void write_hello_lua() {
        40      lua_State *L = luaL_newstate(); 
        41      luaL_openlibs(L);               
        42      
        43      // Open devnull outside of the loop
        44      luaL_loadstring(L, "devnull = io.open('/dev/null', 'w')");  // Open /dev/null before the loop
        45      lua_pcall(L, 0, 0, 0);
        46
        47      char lua_script[200];
        48      snprintf(lua_script, sizeof(lua_script), "for i = 1, %d do devnull:write('hello world from Lua\\n') end", NUM_ITERATIONS);
        49     
        50      if (luaL_loadbuffer(L, lua_script, strlen(lua_script), "hello_world_lua") != LUA_OK) {
        51          fprintf(stderr, "Error: %s\n", lua_tostring(L, -1));
        52      }
        53
        54      lua_pcall(L, 0, 0, 0); // Execute the loaded Lua script
        55
        56      // Close devnull after the loop
        57      luaL_loadstring(L, "devnull:close()"); // Close /dev/null after the loop
        58      lua_pcall(L, 0, 0, 0);
        59
        60      lua_close(L);
        61  }
        62
        63  // Function to write "hello world" to /dev/null using Python
        64  void write_hello_python() {
        65      PyRun_SimpleString(
        66          "import os\n"
        67          "with open(os.devnull, 'w') as devnull:\n"
        68          "    for i in range(10000):\n"
        69          "        print('hello world from Python', file=devnull)"
        70      );
        71  }
        72
        73  int main(int argc, char *argv[]) {
        74      (void)argc; // unused parameter
        75      (void)argv; // unused parameter
        76
        77      Py_Initialize();
        78      
        79      double c_time = measure_time(write_hello_c, NULL); 
        80      double lua_time = measure_time(write_hello_lua, NULL); 
        81      double python_time = measure_time(write_hello_python, NULL); 
        82      
        83      Py_Finalize();
        84
        85      // Measure and print times and calculate ratios
        86      printf("C average time: %f seconds\n", c_time);
        87      printf("Lua average time: %f seconds\n", lua_time); 
        88      printf("Python average time: %f seconds\n", python_time);
        89
        90      if (c_time == 0 || lua_time == 0) {
        91          printf("Division by zero would occur, so no comparison is made.\n");
        92      } else {
        93          printf("C is %.2f times faster than Lua\n", lua_time / c_time);
        94          printf("Lua is %.2f times faster than Python\n", python_time / lua_time);
        95      }
        96
        97      return 0;
        98  }
        99
    root@lol ~/c-luajit-python # gcc -o hello_world_files_lua hello_world_files_lua-10.0.c -I/usr/incl
    ude/python3.12 -L/usr/lib/python3.12 -lpython3.12 -llua5.3
    root@lol ~/c-luajit-python # ./hello_world_files_lua
    C average time: 0.000126 seconds
    Lua average time: 0.000782 seconds
    Python average time: 0.003371 seconds
    C is 6.21 times faster than Lua
    Lua is 4.31 times faster than Python
    root@lol ~/c-luajit-python # 
    

    I hope everyone gets the servers they want!

  • Not_OlesNot_Oles Hosting ProviderContent Writer
    edited July 9
    root@lol ~/c-luajit-python # cat -n hello_world_files_luajit-10.0.c 
         1  #include <stdio.h>
         2  #include <string.h>  // for strlen
         3  #include <time.h>    // for clock, CLOCKS_PER_SEC
         4  #include <Python.h>  // for Python C API
         5
         6  #include <luajit-2.1/lua.h>   // Include LuaJIT headers
         7  #include <luajit-2.1/lauxlib.h>
         8  #include <luajit-2.1/lualib.h>
         9
        10  #define NUM_ITERATIONS 10000 // Number of iterations for each language
        11
        12  // Function to measure execution time with an additional void pointer argument
        13  double measure_time(void (*func)(void *), void *arg) {
        14      clock_t start, end;
        15      double cpu_time_used;
        16
        17      start = clock();
        18      func(arg); // Call the function with its argument
        19      end = clock();
        20      cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
        21      return cpu_time_used;
        22  }
        23
        24  // Function to write "hello world" to /dev/null using C 
        25  void write_hello_c() {
        26      FILE *dev_null = fopen("/dev/null", "w");
        27      for (int i = 0; i < NUM_ITERATIONS; i++) {
        28          fprintf(dev_null, "hello world from C\n");
        29      }
        30      fclose(dev_null);
        31  }
        32
        33  // Function to write "hello world" to /dev/null using LuaJIT
        34  void write_hello_lua() {
        35      lua_State *L = luaL_newstate(); 
        36      luaL_openlibs(L);               
        37
        38      // Open devnull outside of the loop
        39      luaL_loadstring(L, "devnull = io.open('/dev/null', 'w')");  
        40      lua_pcall(L, 0, 0, 0);
        41
        42      char lua_script[200];
        43      snprintf(lua_script, sizeof(lua_script), "for i = 1, %d do devnull:write('hello world from LuaJIT\\n') end", NUM_ITERATIONS);
        44     
        45      if (luaL_loadbuffer(L, lua_script, strlen(lua_script), "hello_world_lua") != LUA_OK) {
        46          fprintf(stderr, "Error: %s\n", lua_tostring(L, -1));
        47      }
        48
        49      lua_pcall(L, 0, 0, 0);
        50
        51      // Close devnull after the loop
        52      luaL_loadstring(L, "devnull:close()"); 
        53      lua_pcall(L, 0, 0, 0);
        54
        55      lua_close(L);
        56  }
        57
        58  // Function to write "hello world" to /dev/null using Python
        59  void write_hello_python() {
        60      PyRun_SimpleString(
        61          "import os\n"
        62          "with open(os.devnull, 'w') as devnull:\n"
        63          "    for i in range(10000):\n"
        64          "        print('hello world from Python', file=devnull)"
        65          );
        66  }
        67
        68  int main() {
        69
        70      Py_Initialize();
        71      
        72      double c_time = measure_time(write_hello_c, NULL); 
        73      double lua_time = measure_time(write_hello_lua, NULL); 
        74      double python_time = measure_time(write_hello_python, NULL); 
        75      
        76      Py_Finalize();
        77
        78      // Measure and print times and calculate ratios
        79      printf("C average time: %f seconds\n", c_time);
        80      printf("LuaJIT average time: %f seconds\n", lua_time); 
        81      printf("Python average time: %f seconds\n", python_time);
        82
        83      if (c_time == 0 || lua_time == 0) {
        84          printf("Division by zero would occur, so no comparison is made.\n");
        85      } else {
        86          printf("C is %.2f times faster than LuaJIT\n", lua_time / c_time);
        87          printf("LuaJIT is %.2f times faster than Python\n", python_time / lua_time);
        88      }
        89
        90      return 0;
        91  }
    root@lol ~/c-luajit-python # gcc -o hello_world_files_luajit hello_world_files_luajit-10.0.c -I/us
    r/include/python3.12 -L/usr/lib/python3.12 -lpython3.12 -lluajit-5.1
    root@lol ~/c-luajit-python # ./hello_world_files_luajit 
    C average time: 0.000071 seconds # Was 0.000126 seconds
    LuaJIT average time: 0.000184 seconds # Was Lua 0.000782 seconds, now LuaJIT
    Python average time: 0.002267 seconds # Was 0.003371 seconds
    C is 2.59 times faster than LuaJIT
    LuaJIT is 12.32 times faster than Python
    root@lol ~/c-luajit-python # 
    
    Thanked by (1)cmeerw

    I hope everyone gets the servers they want!

  • Not_OlesNot_Oles Hosting ProviderContent Writer
    edited July 9

    I ran three sets, each set consisting of the two programs compiled from the above hello_world_files_lua-10.0.c and hello_world_files_luajit-10.0.c source code. The file results2 shown at the end of this post contains the complete output of all three sets. Prior to the results2 file, there are shown greps of the C, Lua, LuaJIT, and Python average execution time results.

    Can somebody please explain to me why the average execution times vary so much?

    Could the variance be caused by the fast and slow cores on the i9-13900?

    The server isn't busy, so other work probably is not a factor.

    Thanks! Much appreciated! <3

    root@lol ~/c-luajit-python # grep C\ average\ time results2
    C average time: 0.000121 seconds
    C average time: 0.000111 seconds
    C average time: 0.000111 seconds
    C average time: 0.000069 seconds
    C average time: 0.000111 seconds
    C average time: 0.000068 seconds
    root@lol ~/c-luajit-python # 
    
    root@lol ~/c-luajit-python # grep Lua\ average\ time results2
    Lua average time: 0.000882 seconds
    Lua average time: 0.000751 seconds
    Lua average time: 0.000776 seconds
    root@lol ~/c-luajit-python # 
    
    root@lol ~/c-luajit-python # grep LuaJIT\ average\ time results2
    LuaJIT average time: 0.000278 seconds
    LuaJIT average time: 0.000184 seconds
    LuaJIT average time: 0.000171 seconds
    root@lol ~/c-luajit-python # 
    
    root@lol ~/c-luajit-python # grep Python\ average\ time results2
    Python average time: 0.002796 seconds
    Python average time: 0.003480 seconds
    Python average time: 0.003593 seconds
    Python average time: 0.002328 seconds
    Python average time: 0.003397 seconds
    Python average time: 0.002306 seconds
    root@lol ~/c-luajit-python # 
    
    root@lol ~/c-luajit-python # cat results2
    root@lol ~/c-luajit-python # ./hello_world_files_lua
    C average time: 0.000121 seconds
    Lua average time: 0.000882 seconds
    Python average time: 0.002796 seconds
    C is 7.29 times faster than Lua
    Lua is 3.17 times faster than Python
    root@lol ~/c-luajit-python # ./hello_world_files_luajit 
    C average time: 0.000111 seconds
    LuaJIT average time: 0.000278 seconds
    Python average time: 0.003480 seconds
    C is 2.50 times faster than LuaJIT
    LuaJIT is 12.52 times faster than Python
    root@lol ~/c-luajit-python # ./hello_world_files_lua
    C average time: 0.000111 seconds
    Lua average time: 0.000751 seconds
    Python average time: 0.003593 seconds
    C is 6.77 times faster than Lua
    Lua is 4.78 times faster than Python
    root@lol ~/c-luajit-python # ./hello_world_files_luajit 
    C average time: 0.000069 seconds
    LuaJIT average time: 0.000184 seconds
    Python average time: 0.002328 seconds
    C is 2.67 times faster than LuaJIT
    LuaJIT is 12.65 times faster than Python
    root@lol ~/c-luajit-python # ./hello_world_files_lua
    C average time: 0.000111 seconds
    Lua average time: 0.000776 seconds
    Python average time: 0.003397 seconds
    C is 6.99 times faster than Lua
    Lua is 4.38 times faster than Python
    root@lol ~/c-luajit-python # ./hello_world_files_luajit 
    C average time: 0.000068 seconds
    LuaJIT average time: 0.000171 seconds
    Python average time: 0.002306 seconds
    C is 2.51 times faster than LuaJIT
    LuaJIT is 13.49 times faster than Python
    root@lol ~/c-luajit-python # 
    root@lol ~/c-luajit-python # 
    

    I hope everyone gets the servers they want!

  • Not_OlesNot_Oles Hosting ProviderContent Writer
    edited July 12
    Thanked by (1)tmntwitw

    I hope everyone gets the servers they want!

Sign In or Register to comment.