| 1 |
#!@PYTHON@ |
| 2 |
|
| 3 |
# SPDX-License-Identifier: BSD-3-Clause |
| 4 |
# Copyright Contributors to the OpenEXR Project. |
| 5 |
|
| 6 |
import random |
| 7 |
import sys |
| 8 |
import time |
| 9 |
import numpy as np |
| 10 |
|
| 11 |
from imath import * |
| 12 |
|
| 13 |
X = 1000000 |
| 14 |
f = open("time_trials.csv", "a") |
| 15 |
all_tests = {} |
| 16 |
|
| 17 |
def time_operation(func): |
| 18 |
tested_inputs = all_tests[func] |
| 19 |
for tested_input in tested_inputs: |
| 20 |
arg_string = "" |
| 21 |
for arg in tested_input: |
| 22 |
arg_string += type(arg).__name__ + " " |
| 23 |
f.write(func.__name__+": "+arg_string) # generates unique description |
| 24 |
start_time = time.clock_gettime(4) |
| 25 |
func(tested_input) |
| 26 |
f.write(","+repr(time.clock_gettime(4) - start_time)+"\n") |
| 27 |
|
| 28 |
#MULTIPLICAITON TESTING |
| 29 |
|
| 30 |
def time_multVecMatrix(test_input): |
| 31 |
mat = test_input[0] |
| 32 |
vArray = test_input[1] |
| 33 |
x = mat.multVecMatrix(vArray) |
| 34 |
|
| 35 |
def time_multDirMatrix(test_input): |
| 36 |
mat = test_input[0] |
| 37 |
vArray = test_input[1] |
| 38 |
x = mat.multDirMatrix(vArray) |
| 39 |
|
| 40 |
m44f = M44f(5,6,6,8, 2,2,2,8, 6,6,2,8, 2,3,6,7) |
| 41 |
v3fa = V3fArray(X) |
| 42 |
v3fa[:] = V3f(1,1,1) |
| 43 |
|
| 44 |
m33f = M33f(5,6,6, 2,2,2, 6,6,2) |
| 45 |
v2fa = V2fArray(X) |
| 46 |
v2fa[:] = V2f(1,1) |
| 47 |
|
| 48 |
m44d = M44d(5,6,6,8, 2,2,2,8, 6,6,2,8, 2,3,6,7) |
| 49 |
v3da = V3dArray(X) |
| 50 |
v3da[:] = V3d(1,1,1) |
| 51 |
|
| 52 |
m33d = M33d(1,0,5, 2,1,6, 3,4,0) |
| 53 |
v2da = V2dArray(X) |
| 54 |
v2da[:] = V2d(1,1) |
| 55 |
|
| 56 |
tests_multMatrix = [[m44f, v3fa], |
| 57 |
[m33f, v2fa], |
| 58 |
[m44d, v3da], |
| 59 |
[m33d, v2da]] |
| 60 |
|
| 61 |
all_tests[time_multVecMatrix] = tests_multMatrix |
| 62 |
all_tests[time_multDirMatrix] = tests_multMatrix |
| 63 |
|
| 64 |
#INVERT TESTING |
| 65 |
|
| 66 |
def time_inverse(test_input): |
| 67 |
mata = test_input[0] |
| 68 |
x = mata.inverse() |
| 69 |
|
| 70 |
def time_invert(test_input): |
| 71 |
mata = test_input[0] |
| 72 |
mata.invert() |
| 73 |
|
| 74 |
def time_gjInverse(test_input): |
| 75 |
mata = test_input[0] |
| 76 |
x = mata.gjInverse() |
| 77 |
|
| 78 |
def time_gjInvert(test_input): |
| 79 |
mata = test_input[0] |
| 80 |
mata.gjInvert() |
| 81 |
|
| 82 |
|
| 83 |
m22f = M22f(4.0,7.0, 2.0,6.0) |
| 84 |
m22d = M22d(4.0,7.0, 2.0,6.0) |
| 85 |
|
| 86 |
m22fa = M22fArray(X) |
| 87 |
m22fa[:] = m22f |
| 88 |
m22da = M22dArray(X) |
| 89 |
m22da[:] = m22d |
| 90 |
m33fa = M33fArray(X) |
| 91 |
m33fa[:] = m33f |
| 92 |
m33da = M33dArray(X) |
| 93 |
m33da[:] = m33d |
| 94 |
m44fa = M44fArray(X) |
| 95 |
m44fa[:] = m44f |
| 96 |
m44da = M44dArray(X) |
| 97 |
m44da[:] = m44d |
| 98 |
|
| 99 |
tests_inver = [[m44fa], |
| 100 |
[m33fa], |
| 101 |
[m22fa], |
| 102 |
[m44da], |
| 103 |
[m33da], |
| 104 |
[m22da]] |
| 105 |
|
| 106 |
tests_gjInver = [[m44fa], |
| 107 |
[m33fa], |
| 108 |
[m44da], |
| 109 |
[m33da]] |
| 110 |
|
| 111 |
all_tests[time_inverse] = tests_inver |
| 112 |
all_tests[time_invert] = tests_inver |
| 113 |
all_tests[time_gjInverse] = tests_gjInver |
| 114 |
all_tests[time_gjInvert] = tests_gjInver |
| 115 |
|
| 116 |
# NORMALIZE TEST |
| 117 |
|
| 118 |
def time_normalize(test_input): |
| 119 |
vArray = test_input[0] |
| 120 |
vArray.normalize() |
| 121 |
|
| 122 |
def time_normalizeExc(test_input): |
| 123 |
vArray = test_input[0] |
| 124 |
vArray.normalizeExc() |
| 125 |
|
| 126 |
def time_normalized(test_input): |
| 127 |
vArray = test_input[0] |
| 128 |
x = vArray.normalized() |
| 129 |
|
| 130 |
def time_normalizedExc(test_input): |
| 131 |
vArray = test_input[0] |
| 132 |
x = vArray.normalizedExc() |
| 133 |
|
| 134 |
v4fa = V4fArray(X) |
| 135 |
v4fa[:] = V4f(1,1,1,1) |
| 136 |
|
| 137 |
v4da = V4dArray(X) |
| 138 |
v4da[:] = V4d(1,1,1,1) |
| 139 |
|
| 140 |
tests_normalize = [[v2fa], |
| 141 |
[v2da], |
| 142 |
[v3fa], |
| 143 |
[v3da], |
| 144 |
[v4fa], |
| 145 |
[v4da]] |
| 146 |
|
| 147 |
all_tests[time_normalize] = tests_normalize |
| 148 |
all_tests[time_normalizeExc] = tests_normalize |
| 149 |
all_tests[time_normalized] = tests_normalize |
| 150 |
all_tests[time_normalizedExc] = tests_normalize |
| 151 |
|
| 152 |
# SHEAR TEST |
| 153 |
|
| 154 |
def time_shear(test_input): |
| 155 |
mat = test_input[0] |
| 156 |
shear_in = test_input[1] |
| 157 |
for i in range(0,X): |
| 158 |
x = mat.shear(shear_in) |
| 159 |
|
| 160 |
all_tests[time_shear] = [[m44f, (1,2,3)], |
| 161 |
[m44d, (1,2,3)], |
| 162 |
[m33f, (1,2)], |
| 163 |
[m33d, (1,2)], |
| 164 |
[m44f, V3f(1,2,3)], |
| 165 |
[m44d, V3d(1,2,3)], |
| 166 |
[m33f, V2f(1,2)], |
| 167 |
[m33d, V2d(1,2)]] |
| 168 |
#TODO: add Shear6<T> |
| 169 |
|
| 170 |
# SCALE TEST |
| 171 |
|
| 172 |
def time_scale(test_input): |
| 173 |
mat = test_input[0] |
| 174 |
scale_in = test_input[1] |
| 175 |
for i in range(0,X): |
| 176 |
x = mat.scale(scale_in) |
| 177 |
#TODO: determine significance of Python bytcode impact on speed |
| 178 |
|
| 179 |
all_tests[time_scale] = [[m44f, 2.0], |
| 180 |
[m44d, 2.0], |
| 181 |
[m33f, 2.0], |
| 182 |
[m33d, 2.0], |
| 183 |
[m22f, 2.0], |
| 184 |
[m22d, 2.0]] |
| 185 |
|
| 186 |
# TRANSLATION TEST |
| 187 |
|
| 188 |
def time_translate(test_input): |
| 189 |
mat = test_input[0] |
| 190 |
trans_in = test_input[1] |
| 191 |
for i in range(0,X): |
| 192 |
x = mat.translate(trans_in) |
| 193 |
|
| 194 |
all_tests[time_translate] = [[m44f, V3f(1,1,1)], |
| 195 |
[m44d, V3d(1,1,1)], |
| 196 |
[m33f, V2f(1,1)], |
| 197 |
[m33d, V2d(1,1)]] |
| 198 |
|
| 199 |
# FRUSTUM TEST |
| 200 |
|
| 201 |
def time_frustum_init(description, parameters): |
| 202 |
f.write(description) |
| 203 |
start_time = time.clock_gettime(4) |
| 204 |
for i in range(0,X): |
| 205 |
x = Frustum(parameters[0], parameters[1], parameters[2], parameters[3], parameters[4]) |
| 206 |
f.write(","+repr(time.clock_gettime(4) - start_time)+"\n") |
| 207 |
#UNIMPLEMENTED |
| 208 |
|
| 209 |
for func in all_tests: |
| 210 |
time_operation(func) |
| 211 |
|
| 212 |
""" |
| 213 |
def time_NOARRAYvec(test_input): |
| 214 |
mat = test_input[0] |
| 215 |
vec = test_input[1] |
| 216 |
for i in range(0, X): |
| 217 |
x = mat.multVecMatrix(vec) |
| 218 |
|
| 219 |
def time_NOARRAYdir(test_input): |
| 220 |
mat = test_input[0] |
| 221 |
vec = test_input[1] |
| 222 |
for i in range(0, X): |
| 223 |
x = mat.multDirMatrix(vec) |
| 224 |
|
| 225 |
m44f = M44f(5,6,6,8, 2,2,2,8, 6,6,2,8, 2,3,6,7) |
| 226 |
v3f = V3f(1,1,1) |
| 227 |
|
| 228 |
m33f = M33f(5,6,6, 2,2,2, 6,6,2) |
| 229 |
v2f = V2f(1,1) |
| 230 |
|
| 231 |
m44d = M44d(5,6,6,8, 2,2,2,8, 6,6,2,8, 2,3,6,7) |
| 232 |
v3d = V3d(1,1,1) |
| 233 |
|
| 234 |
m33d = M33d(1,0,5, 2,1,6, 3,4,0) |
| 235 |
v2d = V2d(1,1) |
| 236 |
|
| 237 |
tests_multMatrix = [[m44f, v3f], |
| 238 |
[m33f, v2f], |
| 239 |
[m44d, v3d], |
| 240 |
[m33d, v2d]] |
| 241 |
add_tests = {} |
| 242 |
add_tests[time_NOARRAYvec] = tests_multMatrix |
| 243 |
add_tests[time_NOARRAYdir] = tests_multMatrix |
| 244 |
|
| 245 |
for func in add_tests: |
| 246 |
time_operation(func) |
| 247 |
""" |