In response to Forum_account
Forum_account wrote:
I didn't look through jt_vectors too much, but you call new /vector(x, y) to create a vector.

Ah, those results were from the ProcLib that you linked to. jt_vectors seems to perform worst of all with 0.205 / 1.661
I ran it again and these are the total CPU times for the mob's verbs (the code is below). The self CPU times were consistently negligable. I did three separate trials, in each trial I used each verb 5 times.

jt_gibson       0.311   0.326   0.329
falacy 0.078 0.139 0.095
forum_account 0.079 0.079 0.079
kaiochao 0.016 0 0.015

It seems like using objects means you trigger garbage collection and may not have consistent running times.

I'm impressed with how much better BYOND manages lists than objects. The syntax isn't ideal but it gives you some idea of how much faster built-in vectors could be. Having a built-in vector type would also make it possible to make built-in procs that deal with coordinates, colors, or any set of numbers use vectors (it'd be much nicer if icon.GetPixel() returned a vector instead of a "#RRGGBBAA" string).

Here's the code:

#define DEBUG

proc
falacy()
var/Vector/a = new(rand(), rand())
var/Vector/b = new(rand(), rand())
var/Vector/c = a.Add(b)

forum_account()
var/a = Vec.vec2(rand(), rand())
var/b = Vec.vec2(rand(), rand())
var/c = Vec.add(a, b)

kaiochao()
var/a = new_vec2(rand(), rand())
var/b = new_vec2(rand(), rand())
var/c = vec2_add(a, b)

jt_gibson()
var/vector/a = new(rand(), rand())
var/vector/b = new(rand(), rand())
var/vector/c = a.AddVectors(b)

mob
var
count = 1000

verb
falacy()
for(var/i = 1 to count)
global.falacy()

forum_account()
for(var/i = 1 to count)
global.forum_account()

kaiochao()
for(var/i = 1 to count)
global.kaiochao()

jt_gibson()
for(var/i = 1 to count)
global.jt_gibson()
Page: 1 2