luau/bench/tests/matrixmult.lua

41 lines
1.0 KiB
Lua
Raw Permalink Normal View History

local function prequire(name) local success, result = pcall(require, name); return if success then result else nil end
local bench = script and require(script.Parent.bench_support) or prequire("bench_support") or require("../bench_support")
Sync to upstream/release/576 (#928) * `ClassType` can now have an indexer defined on it. This allows custom types to be used in `t[x]` expressions. * Fixed search for closest executable breakpoint line. Previously, breakpoints might have been skipped in `else` blocks at the end of a function * Fixed how unification is performed for two optional types `a? <: b?`, previously it might have unified either 'a' or 'b' with 'nil'. Note that this fix is not enabled by default yet (see the list in `ExperimentalFlags.h`) In the new type solver, a concept of 'Type Families' has been introduced. Type families can be thought of as type aliases with custom type inference/reduction logic included with them. For example, we can have an `Add<T, U>` type family that will resolve the type that is the result of adding two values together. This will help type inference to figure out what 'T' and 'U' might be when explicit type annotations are not provided. In this update we don't define any type families, but they will be added in the near future. It is also possible for Luau embedders to define their own type families in the global/environment scope. Other changes include: * Fixed scope used to find out which generic types should be included in the function generic type list * Fixed a crash after cyclic bound types were created during unification And in native code generation (jit): * Use of arm64 target on M1 now requires macOS 13 * Entry into native code has been optimized. This is especially important for coroutine call/pcall performance as they involve going through a C call frame * LOP_LOADK(X) translation into IR has been improved to enable type tag/constant propagation * arm64 can use integer immediate values to synthesize floating-point values * x64 assembler removes duplicate 64bit numbers from the data section to save space * Linux `perf` can now be used to profile native Luau code (when running with --codegen-perf CLI argument)
2023-05-13 01:50:47 +08:00
local function mmul(matrix1, matrix2)
local shapeRows = #matrix1
local shapeColumns = #matrix2[1]
local result = table.create(shapeRows)
for i = 1, shapeRows do
result[i] = table.create(shapeColumns)
for j = 1, shapeColumns do
local sum = 0
for k = 1, shapeColumns do
sum = sum + matrix1[i][k] * matrix2[k][j]
end
result[i][j] = sum
end
end
return result
end
function test()
local n = 100
local mat = table.create(n)
for i = 1, n do
local t = table.create(n)
for k = 1, n do
t[k] = math.random()
end
mat[i] = t
end
local startTime = os.clock()
local result = mmul(mat, mat)
return os.clock() - startTime
end
bench.runCode(test, "matrixmult")