luau/bench/tests/vector-math.lua
Alexander Youngblood 0bd9321957 Sync to upstream/release/653
## What's Changed?

* Optimized the vector dot product by up to 24%
* Allow for x/y/z/X/Y/Z vector field access by registering a `vector` metatable
with an `__index` method
* Fixed a bug preventing consistent recovery from parse errors in table types.
* Optimized `k*n` and `k+n` when types are known
* Allow fragment autocomplete to handle cases like the automatic insertion of
parens, keywords, strings, etc., while maintaining a correct relative positioning

 ### New Solver

* Added support for 'thread' and 'buffer' primitive types in Luau user-defined
type functions
* Allow for `nil` assignment to tables and classes with indexers

---------

Co-authored-by: Aaron Weiss <aaronweiss@roblox.com>
Co-authored-by: Andy Friesen <afriesen@roblox.com>
Co-authored-by: Aviral Goel <agoel@roblox.com>
Co-authored-by: Hunter Goldstein <hgoldstein@roblox.com>
Co-authored-by: Varun Saini <vsaini@roblox.com>
Co-authored-by: Vighnesh Vijay <vvijay@roblox.com>
Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com>
2024-11-22 12:37:17 -08:00

39 lines
891 B
Lua

local function prequire(name) local success, result = pcall(require, name); if success then return result end return nil end
local bench = script and require(script.Parent.bench_support) or prequire("bench_support") or require("../bench_support")
function fma(a: vector, b: vector, c: vector)
return a * b + c
end
function approx(a: vector): vector
local r = vector.create(1, 1, 1)
local aa = a
r += aa * 0.123
aa *= a
r += aa * 0.123
aa *= a
r += aa * 0.123
aa *= a
r += aa * 0.123
aa *= a
r += aa * 0.123
aa *= a
r += aa * 0.123
return r
end
function test()
local A = vector.create(1, 2, 3)
local B = vector.create(4, 5, 6)
local C = vector.create(7, 8, 9)
local fma = fma
local approx = approx
for i=1,100000 do
fma(A, B, C)
approx(A)
end
end
bench.runCode(test, "vector-math")