Giter Site home page Giter Site logo

gitspartv / luajit-benchmarks Goto Github PK

View Code? Open in Web Editor NEW
26.0 26.0 0.0 382 KB

LuaJIT Benchmark tests

Home Page: https://gitspartv.github.io/LuaJIT-Benchmarks/

License: Creative Commons Zero v1.0 Universal

HTML 58.52% Lua 39.46% CSS 2.02%
benchmark benchmarking luajit testing

luajit-benchmarks's Introduction

Spar


Languages, technologies, stuff, frameworks and tools I've used in some way:
  • C++, Lua, LuaJIT, C++17, C++20, Python, Plain HTML + CSS + JavaScript, Groovy
  • Boost, telecom (LTE), 3GPP, PostgreSQL, Docker, MySQL, fmt, SQLite, protobuf, webhook, coroutines, async, regex
  • CalDAV, Diameter protocol, WebSocket, SOAP API, JSON, REST API, SVG, XML
  • Compiler development, web scraping (University sites, Cian.ru, various property developer sites, Notion, hh.ru), C++ reverse-engineering/decompilation (x86-64, ARMv7-M) using IDA and Ghidra, DSL, Bot development (Discord, Telegram, VK, Pachca), logging, game server frontend/backend development, optimizations, gamedev, analytics, game UI development
  • Source Engine, Luvit, Raspberry Pi, Nelua, Linux, LÖVE, NodeMCU, Arduino
  • CMake, Conan, Grafana, Prometheus

My Projects:

  • Hanley bot — Successfull pet-project bot written in C++ with over 200 users made for psychology specialists.
  • Lua Patterns — A tool to learn and analyze Lua Patterns.
  • Lua Infographics — Collection of infographics dedicated to Lua (Some serious and just for fun).
  • LuaJIT Benchmarks — A page about optimizing Lua by benchmarking several variants of the same code and finding the best one (among them).
  • LLLua — My language I plan to develop. See the concept for the future version (0.1 version can be already used).
  • luamemprof — Memory profiler module for Lua and LuaJIT.
  • My Discordia Libraries — The open-sourced part of Toolgun bot developed for the Garry's Mod official Discord server. The server has over 80,000 members as yet replacing the need for additional human moderation for more than 3 years. Includes Lua minidump reader library.
  • discordia-slash — Discordia's extension for slash commands.
  • Love2D Framework — Framework with GUI, timers and texture loading libraries based on GMod API.
  • GodSentTools — Series of GMod addons, mainly for art and moviemakers.
  • RemPos — GMod C++ module that connects iOS app with GMod and brings acceleration and gyroscope data.
  • My GMod Libraries — Public libraries I made for my GMod server. Server is dead, but libraries can be used/refactored.
  • University admission advisor — Bot written in Lua with VK API that downloads lists of applicants from different universities with my specialization, parses them and calculates the chance to pass.
  • UniBot — Bot written in Lua with VK API that gives information about the schedule, next lesson and other things.
  • LuaCUE — Corsair Utility Engine module for Lua written in C++.
  • SparTask — Windows taskbar replacement for focusing on specific task, allows putting only necessary icons.

See all repositories...

Important

Since 2017 I've contributed a lot to Garry's Mod. Check out this list as well.

Projects I participated in:

Small projects:

GitHub Stats:

Top Langs

  • 17 PRs for open source projects. Most noticeable contributions is the Garry's Mod codebase.
  • 29 bug reports and suggestions only for Garry's Mod and same amount for other open source projects.
  • HitCount

luajit-benchmarks's People

Contributors

gitspartv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

luajit-benchmarks's Issues

Benchmark 3 doesn't give the same result on my computer.

image

Code 1

-- 91.679 ms on my computer

local get = function(self, idx)
    if type(idx) == "number" then
        idx = idx + 1
    end
    return rawget(self, idx)
end

local set = function(self, idx, val)
    if type(idx) == "number" then
        idx = idx + 1
    end
    rawset(self, idx, val)
end

local utils = { get = get, set = set }

local array = {}

for i = 1, 5000, 1 do
    array[i] = math.random(1000000)
end

len = #array;

for i = 0, len - 2, 1 do
    for j = 0, len - 2 - i, 1 do
        a = utils.get(array, j)
        b = utils.get(array, j + 1)
        if a > b then
            utils.set(array, j, b)
            utils.set(array, j + 1, a)
        end
    end
end

Code 2

-- 100.08 ms on my computer
local get = function(self, idx)
    if type(idx) == "number" then
        idx = idx + 1
    end
    return rawget(self, idx)
end

local set = function(self, idx, val)
    if type(idx) == "number" then
        idx = idx + 1
    end
    rawset(self, idx, val)
end

local utils = { get = get, set = set }

local array = {}

for i = 1, 5000, 1 do
    array[i] = math.random(1000000)
end

len = #array;

for i = 0, len - 2, 1 do
    for j = 0, len - 2 - i, 1 do
        a = get(array, j)
        b = get(array, j + 1)
        if a > b then
            set(array, j, b)
            set(array, j + 1, a)
        end
    end
end

Check out my repo for more details.

Reproducibility

Hello,

It would be sweet if people could see the script used to generate the results and run that script themselves. Manually editing the benchmark script is a slow and error-prone process.

[test2] Instructions outside of the hot loop are counted

https://gitspartv.github.io/LuaJIT-Benchmarks/#test2

The comparison tells the following:

Global table indexing: 38 instructions total.
Local: 18 instructions total.

Diff
  mov dword [0x24660410], 0x1
  movsd xmm7, [rdx+0x40]
  cvttsd2si eax, xmm7
  xorps xmm6, xmm6
  cvtsi2sd xmm6, eax
  ucomisd xmm7, xmm6
  jnz 0x7ffa543c0010        ->0
  jpe 0x7ffa543c0010        ->0
  cmp eax, 0x7ffffffe
  jg 0x7ffa543c0010 ->0
  cvttsd2si edi, [rdx+0x38]
  cmp dword [rdx+0x14], -0x09
- jnz 0x7ffa543c0010        ->0
- cmp dword [rdx+0x10], 0x2467f788
- jnz 0x7ffa543c0010        ->0
- mov ebp, [0x2467f790]
- cmp dword [rbp+0x1c], +0x3f
- jnz 0x7ffa543c0010        ->0
- mov ebx, [rbp+0x14]
- mov rsi, 0xfffffffb24665fd8
- cmp rsi, [rbx+0x518]
- jnz 0x7ffa543c0010        ->0
- cmp dword [rbx+0x514], -0x0c
  jnz 0x7ffa543c0010        ->0
+ cmp dword [rdx+0x18], 0x2466aca0
- mov edx, [rbx+0x510]
- cmp dword [rdx+0x1c], +0x1f
- jnz 0x7ffa543c0010        ->0
- mov ecx, [rdx+0x14]
- mov rsi, 0xfffffffb24666548
- cmp rsi, [rcx+0x230]
- jnz 0x7ffa543c0010        ->0
- cmp dword [rcx+0x22c], -0x09
- jnz 0x7ffa543c0010        ->0
- cmp dword [rcx+0x228], 0x24666520
  jnz 0x7ffa543c0010        ->0
  add edi, +0x01
  cmp edi, eax
  jg 0x7ffa543c0014 ->1

The benchmark counts overall instructions, not only the hot loop. The real performance is the same for both variants (at least for this particular test).

-- luajit-bench-2-v1.lua
local function test()
    local acc = 0
    for i = 1, 10^8 do
        acc = acc + math.sin(3.14)
    end
    return acc
end

print(test())
-- luajit-bench-2-v1.lua
local s = math.sin

local function test()
    local acc = 0
    for i = 1, 10^8 do
        acc = acc + s(3.14)
    end
    return acc
end

print(test())

Curious fact: if I change sin(3.14) to sin(i), the loops in both code variants (and so timings) are still equivalent.

You can easily look at both variants of IR/asm using luajit.me (just replace 10^8 with 10^5 or something like so).

image

image

Side note: It is hard to spot that the diff on the web page shows the code outside of the hot loop. I worth to show more context in the diff at least.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.