-
Notifications
You must be signed in to change notification settings - Fork 7
/
vectorspeed.html
111 lines (93 loc) · 3.34 KB
/
vectorspeed.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<!DOCTYPE html>//
<html>
<head>
<meta charset="utf-8">
<title>QUnit Example</title>
<script type="text/javascript" src="sylvester.src.js"></script>
<script type="text/javascript" src="MooTools-Core-1.5.2.js"></script>
<script type="text/javascript" src="src/lightgl.js"></script>
<script type="text/javascript" src="csg.js"></script>
<script type="text/javascript" src="src/NLA.js"></script>
<script type="text/javascript" src="src/js3d.js"></script>
<link rel="stylesheet" href="qunit-2.0.0.css">
</head>
<body>
<script type="text/javascript">
var count = 500000
var start = new Date().getTime();
var a = Vector.random(3), b = Vector.random(3), c = Vector.random(3)
while (count--) {
// console.log(b.times(a.plus(b).dot(c)))
var d = b.times(a.plus(b).dot(c)).cross(a).length()
} console.log( b.times(a.plus(b).dot(c)).cross(a).length());
var end = new Date().getTime();
var time = end - start;
console.log('Execution time: ' + time + "ms");
var count = 500000
var start = new Date().getTime();
var a = Vector.Random(3), b = Vector.Random(3), c = Vector.Random(3)
while (count--) {
var d = b.times(a.add(b).dot(c)).cross(a).modulus()
}
var end = new Date().getTime();
var time = end - start;
console.log('Execution time: ' + time + "ms");
var count = 500000
var start = new Date().getTime();
var a = GL.Vector.randomDirection(), b = GL.Vector.randomDirection(), c = GL.Vector.randomDirection()
while (count--) {
var d = b.times(a.add(b).dot(c)).cross(a).length()
}
console.log( b.times(a.add(b).dot(c)).cross(a).length());
var end = new Date().getTime();
var time = end - start;
console.log('Execution time: ' + time + "ms");
var count = 500000
var start = new Date().getTime();
var a = NLA.V3.random(), b = NLA.V3.random(), c = NLA.V3.random()
while (count--) {
var d = b.times(a.plus(b).dot(c)).cross(a).length()
}
var end = new Date().getTime();
var time = end - start;
console.log('nla.v3: Execution time: ' + time + "ms");
function vAdd(a, b) {
var v = new Float64Array(3);
v[0]= a[0] + a[0]
v[1]= a[1] + a[1]
v[2]= a[2] + a[2]
return new Vector(v)
}
function vCross(a, v) {
var n = new Float64Array(3)
n[0] = a[1] * b[2] - a[2] * b[1]
n[1] = a[2] * b[0] - a[0] * b[2]
n[2] = a[0] * b[1] - a[1] * b[0]
return new Vector(n)
}
function vTimes(a, val) {
var v = new Float64Array(3);
v[0]= a[0] * val
v[1]= a[1] * val
v[2]= a[2] * val
return new Vector(v)
}
function vDot(u,v) {
return u[0] * v[0] + u[1] * v[1] + u[2] * v[2]
}
function vLength(u) { return Math.sqrt(u[0] * u[0] + u[1] * u[1] + u[2] * u[2])
}
var count = 500000
var start = new Date().getTime();
var a = new Float64Array([Math.random(), Math.random(), Math.random()]),
b = new Float64Array([Math.random(), Math.random(), Math.random()]),
c = new Float64Array([Math.random(), Math.random(), Math.random()])
while (count--) {
var d = vLength(vCross(vTimes(b, vDot(vAdd(a, b), c), a)))
}
var end = new Date().getTime();
var time = end - start;
console.log('Execution time: ' + time + "ms");
</script>
</body>
</html>