vmath/tests/bench.nim
treeform 0f80873e58
vmath 1.0.0 - Breaking Changes. (#29)
# Added a bunch of new types:

Type  | Constructor | Description
------|-------------| ---------------------------------------------------
BVec# | bvec#       | a vector of booleans
IVec# | ivec#       | a vector of signed integers
UVec# | uvec#       | a vector of unsigned integers
Vec#  | vec#        | a vector of single-precision floating-point numbers
DVec# | dvec#       | a vector of double-precision floating-point numbers

## And these types:

NIM     | GLSL   | 2     | 3     | 4     | 9     | 16    | 4     |
--------|--------|-------|-------|-------|-------|-------|-------|
bool    | bool   | BVec2 | BVec3 | BVec4 |       |       |       |
int32   | int    | IVec2 | IVec3 | IVec4 |       |       |       |
uint32  | uint   | UVec2 | UVec3 | UVec4 |       |       |       |
float32 | float  | Vec2  | Vec3  | Vec4  | Mat3  | Mat4  | Quat  |
float64 | double | DVec2 | DVec3 | DVec4 | DMat3 | DMat4 | DQuat |

# 0.x.x to 1.0.0 vmath breaking changes:

* `vec3(v)` no longer works please use `vec3(v.x, v.y, 0)` instead.
* `vec3(v, 0)` no longer works please use `vec3(v.x, v.y, 0)` instead.
* `2 * v` no longer works due to more vec types please use `v * 2` instead.
* `m[15]` no longer works because matrices are now m[x, y].
* Concept of 3x3 rotation 3d matrix was removed.
* `angleBetween` got renamed to `angle(a, b)`
* `scaleMat` got renamed to `scale(v)`
* `rotationMat3` got renamed to `rotate(x)`
2021-03-26 13:58:21 -07:00

51 lines
1.1 KiB
Nim

import benchy, vmath
# TODO: I don't trust these simple benchmarks, make a better test.
# echo "new vmath"
# var v = vec3(1, 2, 3)
# timeIt "+":
# for i in 0 ..< 1_000_000:
# v += vec3(4, 5, 6)
# timeIt "-":
# for i in 0 ..< 1_000_000:
# v -= vec3(4, 5, 6)
# timeIt "*":
# for i in 0 ..< 1_000_000:
# v *= PI
# timeIt "/":
# for i in 0 ..< 1_000_000:
# v /= PI
# timeIt "int +":
# var v = ivec3(1, 2, 3)
# for i in 0 ..< 1_000_000:
# keep v + ivec3(4, 5, 6)
# timeIt "int -":
# var v = ivec3(1, 2, 3)
# for i in 0 ..< 1_000_000:
# keep v - ivec3(4, 5, 6)
timeIt "matrix mat4":
var m = mat4()
for i in 0 ..< 10_000:
m = m *
rotate(0.2.float32, vec3(1, 0, 0)) *
scale(vec3(0.3)) *
translate(vec3(1))
keep m
timeIt "matrix mat3":
var m = mat3()
for i in 0 ..< 10_000:
m = m * rotate(0.2.float32) * scale(vec2(0.3)) * translate(vec2(1))
keep m
timeIt "matrix quat":
var m = rotate(0.2.float32, vec3(1, 0, 0)) * scale(vec3(0.3)) * translate(vec3(1))
for i in 0 ..< 100_000:
keep m.quat().mat4()