Not a member yet? Why not Sign up today
Create an account  

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 
Lua performance analysis

#1
Inspired by Evil4Zerggin, I ran 100,000 iterations of various functions, focusing on vector and math functions (code is below).

+ I:Maths_AngleBetweenVectors(): 34ms
+ Semi-manual angle between vectors (math.acos(Vector3.Dot(a[i],b[i]) / (Vector3.Magnitude(a[i]) * Vector3.Magnitude(b[i])))): 6.7ms
+ Vector addition: highly variable (?), ~4ms
+ Vector multiplication by scalar: highly variable, ~3ms
+ Vector3.Magnitude: 1.1ms
+ Vector3.Normalized: 1.5ms
+ Vector3.Angle: Namespace error (!)
+ Vector3.Project: ~4ms
+ Manual vector addition (not reformed): 1.2ms
+ Manual vector addition (reformed): ~4ms
+ projection (a+b*2): ~4ms
+ Manual projection (not reformed): 1.2ms
+ Manual projection (reformed): ~4ms
+ Quaternion.LookRotation: ~45ms
+ Vector3.Distance: 1.2ms
+ Manual distance: 1.2ms

This definitely suggests that vectors carry with them the magnitude and normalized variables, and update them stupidly (in the case of multiplication by scalar). The extreme variability is odd, and unexplained (it should not be hammering the GC, I think...). For now, I think the lesson is to minimize vector code, and to do manual computations if you can get away without reforming them. Also, avoid I:Maths_AngleBetweenVectors and quaternions at all costs (although the manual angle computation is not all that bad; in either event, time to rewrite my missile code).

Code:
a = {}
b = {}
N = 100000

for i = 1, N do
  a[i] = Vector3(math.random(), math.random(), math.random())
  b[i] = Vector3(math.random(), math.random(), math.random())
end

function Update(I)
  for i = 1, N do
--    x = a[i].x + b[i].x * 2
--    y = a[i].y + b[i].y * 2
--    z = a[i].z + b[i].z * 2
--    c = Vector3(x,y,z)
    c = math.sqrt(a[i].x^2 + a[i].y^2 + a[i].z^2)
  end
end
Allr andask.
Reply



Messages In This Thread
Lua performance analysis - by Blothorn - 2015-09-27, 03:41 PM
RE: Lua performance analysis - by UNAVAILABLE - 2015-09-28, 05:42 AM
RE: Lua performance analysis - by Blothorn - 2015-09-28, 05:48 AM
RE: Lua performance analysis - by Evil4Zerggin - 2015-09-28, 06:35 PM
RE: Lua performance analysis - by Softie - 2015-09-28, 06:58 PM
RE: Lua performance analysis - by Loki - 2015-09-28, 07:43 PM
RE: Lua performance analysis - by Softie - 2015-09-29, 08:37 AM
RE: Lua performance analysis - by Exitius III - 2015-09-28, 08:34 PM
RE: Lua performance analysis - by Blothorn - 2015-09-28, 09:14 PM
RE: Lua performance analysis - by Evil4Zerggin - 2015-09-30, 11:15 PM
RE: Lua performance analysis - by Softie - 2015-10-06, 08:13 PM
RE: Lua performance analysis - by Blothorn - 2015-09-30, 11:34 PM
RE: Lua performance analysis - by Evil4Zerggin - 2015-10-06, 09:07 PM
RE: Lua performance analysis - by Blothorn - 2015-10-11, 08:53 PM
RE: Lua performance analysis - by Softie - 2015-10-11, 08:56 PM
RE: Lua performance analysis - by Blothorn - 2015-10-11, 09:50 PM
RE: Lua performance analysis - by Softie - 2015-10-11, 09:55 PM
RE: Lua performance analysis - by Blothorn - 2015-10-11, 10:25 PM
RE: Lua performance analysis - by Softie - 2015-10-11, 10:26 PM
RE: Lua performance analysis - by Softie - 2015-10-14, 03:32 AM
RE: Lua performance analysis - by Diche_Bach - 2018-08-01, 05:30 AM
RE: Lua performance analysis - by HerpeDerp - 2018-08-05, 04:43 PM

Forum Jump:


Users browsing this thread:
1 Guest(s)