HTML Preparation code:
x
 
1
<script>"use strict";  //ECMAscript 5
2
3
var M3_0 = {
4
    newIdentity: function(){
5
        return {
6
            x1:1., x2:0., x3:0.,
7
            y1:0., y2:1., y3:0.,
8
            z1:0., z2:0., z3:1.};
9
    },
10
    setIdentity: function(m){
11
        m.x1=1., m.x2=0., m.x3=0.;
12
        m.y1=0., m.y2=1., m.y3=0.;
13
        m.z1=0., m.z2=0., m.z3=1.;
14
15
        return m;
16
    },
17
    newVal: function(
18
            x1,x2,x3,
19
            y1,y2,y3,
20
            z1,z2,z3){
21
        return {
22
            x1:x1, x2:x2, x3:x3,
23
            y1:y1, y2:y2, y3:y3,
24
            z1:z1, z2:z2, z3:z3};
25
    },
26
    setVal: function( m,
27
            x1,x2,x3,
28
            y1,y2,y3,
29
            z1,z2,z3){
30
        m.x1=x1, m.x2=x2, m.x3=x3;
31
        m.y1=y1, m.y2=y2, m.y3=y3;
32
        m.z1=z1, m.z2=z2, m.z3=z3;
33
34
        return m;
35
    },
36
    newClone: function(m){
37
        return {
38
            x1:m.x1, x2:m.x2, x3:m.x3,
39
            y1:m.y1, y2:m.y2, y3:m.y3,
40
            z1:m.z1, z2:m.z2, z3:m.z3};
41
    },
42
    setCopy: function(src, dst){
43
        dst.x1=src.x1, dst.x2=src.x2, dst.x3=src.x3;
44
        dst.y1=src.y1, dst.y2=src.y2, dst.y3=src.y3;
45
        dst.z1=src.z1, dst.z2=src.z2, dst.z3=src.z3;
46
47
        return dst;
48
    },
49
    mul_a: function(a,b, out){
50
        // hint for optimizing compiler about aliasing (pointer aliasing)
51
        // https://en.wikipedia.org/wiki/Aliasing_(computing)?oldid=931708672#Conflicts_with_optimization
52
        if(b !== out){ // a==b   => a!=out
53
                       // a==out => a!=b
54
55
            var      a1=a.x1,  a2=a.x2,  a3=a.x3;
56
            out.x1 = a1*b.x1 + a2*b.y1 + a3*b.z1;
57
            out.x2 = a1*b.x2 + a2*b.y2 + a3*b.z2;
58
            out.x3 = a1*b.x3 + a2*b.y3 + a3*b.z3;
59
60
                     a1=a.y1,  a2=a.y2,  a3=a.y3;
61
            out.y1 = a1*b.x1 + a2*b.y1 + a3*b.z1;
62
            out.y2 = a1*b.x2 + a2*b.y2 + a3*b.z2;
63
            out.y3 = a1*b.x3 + a2*b.y3 + a3*b.z3;
64
65
                     a1=a.z1,  a2=a.z2,  a3=a.z3;
66
            out.z1 = a1*b.x1 + a2*b.y1 + a3*b.z1;
67
            out.z2 = a1*b.x2 + a2*b.y2 + a3*b.z2;
68
            out.z3 = a1*b.x3 + a2*b.y3 + a3*b.z3;
69
70
            return out;
71
        } else if(a !== b){ // a!=out
72
            return M3_0.mul_b(a,b, out);
73
        } else { // a==out==b
74
            return M3_0.mul_a(a,M3_0.newClone(a), a); //or M3_0.setCopy(M3_0.mul_a(a,a, {}), a)  - need to bench
75
        }
76
    },
77
    mul_b: function(a,b, out){
78
        // hint for optimizing compiler about aliasing (pointer aliasing)
79
        // https://en.wikipedia.org/wiki/Aliasing_(computing)?oldid=931708672#Conflicts_with_optimization
80
        if(a !== out){ // b==a   => b!=out
81
                       // b==out => b!=a
82
83
            var      bx=b.x1,  by=b.y1,  bz=b.z1;
84
            out.x1 = bx*a.x1 + by*a.x2 + bz*a.x3;
85
            out.y1 = bx*a.y1 + by*a.y2 + bz*a.y3;
86
            out.z1 = bx*a.z1 + by*a.z2 + bz*a.z3;
87
88
                     bx=b.x2,  by=b.y2,  bz=b.z2;
89
            out.x2 = bx*a.x1 + by*a.x2 + bz*a.x3;
90
            out.y2 = bx*a.y1 + by*a.y2 + bz*a.y3;
91
            out.z2 = bx*a.z1 + by*a.z2 + bz*a.z3;
92
93
                     bx=b.x3,  by=b.y3,  bz=b.z3;
94
            out.x3 = bx*a.x1 + by*a.x2 + bz*a.x3;
95
            out.y3 = bx*a.y1 + by*a.y2 + bz*a.y3;
96
            out.z3 = bx*a.z1 + by*a.z2 + bz*a.z3;
97
98
            return out;
99
        } else if(b !== a){ // b!=out
100
            return M3_0.mul_a(a,b, out);
101
        } else { // a==out==b
102
            return M3_0.mul_a(a,M3_0.newClone(a), a); //or M3_0.setCopy(M3_0.mul_a(a,a, {}), a)  - need to bench
103
        }
104
    }
105
};
106
107
var M3_1 = function(
108
        x1,x2,x3,
109
        y1,y2,y3,
110
        z1,z2,z3){
111
    //if(this instanceof M3_1){
112
        this.x1=x1, this.x2=x2, this.x3=x3;
113
        this.y1=y1, this.y2=y2, this.y3=y3;
114
        this.z1=z1, this.z2=z2, this.z3=z3;
115
    //} else {
116
    //  return new M3_1(
117
    //      x1,x2,x3,
118
    //      y1,y2,y3,
119
    //      z1,z2,z3);
120
    //}
121
};
122
123
M3_1.newIdentity = function(){
124
    return new M3_1(
125
        1.,0.,0.,
126
        0.,1.,0.,
127
        0.,0.,1.);
128
};
129
M3_1.setIdentity = function(m){
130
    m.x1=1., m.x2=0., m.x3=0.;
131
    m.y1=0., m.y2=1., m.y3=0.;
132
    m.z1=0., m.z2=0., m.z3=1.;
133
134
    return m;
135
};
136
M3_1.setVal = function( m,
137
        x1,x2,x3,
138
        y1,y2,y3,
139
        z1,z2,z3){
140
    m.x1=x1, m.x2=x2, m.x3=x3;
141
    m.y1=y1, m.y2=y2, m.y3=y3;
142
    m.z1=z1, m.z2=z2, m.z3=z3;
143
144
    return m;
145
};
146
M3_1.newClone = function(m){
147
    return new M3_1(
148
        m.x1, m.x2, m.x3,
149
        m.y1, m.y2, m.y3,
150
        m.z1, m.z2, m.z3);
151
},
152
M3_1.setCopy = function(src, dst){
153
    dst.x1=src.x1, dst.x2=src.x2, dst.x3=src.x3;
154
    dst.y1=src.y1, dst.y2=src.y2, dst.y3=src.y3;
155
    dst.z1=src.z1, dst.z2=src.z2, dst.z3=src.z3;
156
157
    return dst;
158
};
159
M3_1.mul_a = function(a,b, out){
160
    // hint for optimizing compiler about aliasing (pointer aliasing)
161
    // https://en.wikipedia.org/wiki/Aliasing_(computing)?oldid=931708672#Conflicts_with_optimization
162
    if(b !== out){ // a==b   => a!=out
163
                   // a==out => a!=b
164
165
        var      a1=a.x1,  a2=a.x2,  a3=a.x3;
166
        out.x1 = a1*b.x1 + a2*b.y1 + a3*b.z1;
167
        out.x2 = a1*b.x2 + a2*b.y2 + a3*b.z2;
168
        out.x3 = a1*b.x3 + a2*b.y3 + a3*b.z3;
169
170
                 a1=a.y1,  a2=a.y2,  a3=a.y3;
171
        out.y1 = a1*b.x1 + a2*b.y1 + a3*b.z1;
172
        out.y2 = a1*b.x2 + a2*b.y2 + a3*b.z2;
173
        out.y3 = a1*b.x3 + a2*b.y3 + a3*b.z3;
174
175
                 a1=a.z1,  a2=a.z2,  a3=a.z3;
176
        out.z1 = a1*b.x1 + a2*b.y1 + a3*b.z1;
177
        out.z2 = a1*b.x2 + a2*b.y2 + a3*b.z2;
178
        out.z3 = a1*b.x3 + a2*b.y3 + a3*b.z3;
179
180
        return out;
181
    } else if(a !== b){ // a!=out
182
        return M3_1.mul_b(a,b, out);
183
    } else { // a==out==b
184
        return M3_1.mul_a(a,M3_1.newClone(a), a); //or M3_1.setCopy(M3_1.mul_a(a,a, {}), a)  - need to bench
185
    }
186
};
187
M3_1.mul_b = function(a,b, out){
188
    // hint for optimizing compiler about aliasing (pointer aliasing)
189
    // https://en.wikipedia.org/wiki/Aliasing_(computing)?oldid=931708672#Conflicts_with_optimization
190
    if(a !== out){ // b==a   => b!=out
191
                   // b==out => b!=a
192
193
        var      bx=b.x1,  by=b.y1,  bz=b.z1;
194
        out.x1 = bx*a.x1 + by*a.x2 + bz*a.x3;
195
        out.y1 = bx*a.y1 + by*a.y2 + bz*a.y3;
196
        out.z1 = bx*a.z1 + by*a.z2 + bz*a.z3;
197
198
                 bx=b.x2,  by=b.y2,  bz=b.z2;
199
        out.x2 = bx*a.x1 + by*a.x2 + bz*a.x3;
200
        out.y2 = bx*a.y1 + by*a.y2 + bz*a.y3;
201
        out.z2 = bx*a.z1 + by*a.z2 + bz*a.z3;
202
203
                 bx=b.x3,  by=b.y3,  bz=b.z3;
204
        out.x3 = bx*a.x1 + by*a.x2 + bz*a.x3;
205
        out.y3 = bx*a.y1 + by*a.y2 + bz*a.y3;
206
        out.z3 = bx*a.z1 + by*a.z2 + bz*a.z3;
207
208
        return out;
209
    } else if(b !== a){ // b!=out
210
        return M3_1.mul_a(a,b, out);
211
    } else { // a==out==b
212
        return M3_1.mul_a(a,M3_1.newClone(a), a); //or M3_1.setCopy(M3_1.mul_a(a,a, {}), a)  - need to bench
213
    }
214
};
215
216
var M3_2 = {
217
    newIdentity: function(){
218
        return M3_2.newVal(
219
            1.,0.,0.,
220
            0.,1.,0.,
221
            0.,0.,1.);
222
    },
223
    setIdentity: function(m){
224
        m.x1=1., m.x2=0., m.x3=0.;
225
        m.y1=0., m.y2=1., m.y3=0.;
226
        m.z1=0., m.z2=0., m.z3=1.;
227
228
        return m;
229
    },
230
    newVal: function(
231
            x1,x2,x3,
232
            y1,y2,y3,
233
            z1,z2,z3){
234
        return {
235
            x1:x1, x2:x2, x3:x3,
236
            y1:y1, y2:y2, y3:y3,
237
            z1:z1, z2:z2, z3:z3};
238
    },
239
    setVal: function( m,
240
            x1,x2,x3,
241
            y1,y2,y3,
242
            z1,z2,z3){
243
        m.x1=x1, m.x2=x2, m.x3=x3;
244
        m.y1=y1, m.y2=y2, m.y3=y3;
245
        m.z1=z1, m.z2=z2, m.z3=z3;
246
247
        return m;
248
    },
249
    newClone: function(m){
250
        return M3_2.newVal(
251
            m.x1, m.x2, m.x3,
252
            m.y1, m.y2, m.y3,
253
            m.z1, m.z2, m.z3);
254
    },
255
    setCopy: function(src, dst){
256
        dst.x1=src.x1, dst.x2=src.x2, dst.x3=src.x3;
257
        dst.y1=src.y1, dst.y2=src.y2, dst.y3=src.y3;
258
        dst.z1=src.z1, dst.z2=src.z2, dst.z3=src.z3;
259
260
        return dst;
261
    },
262
    mul_a: function(a,b, out){
263
        // hint for optimizing compiler about aliasing (pointer aliasing)
264
        // https://en.wikipedia.org/wiki/Aliasing_(computing)?oldid=931708672#Conflicts_with_optimization
265
        if(b !== out){ // a==b   => a!=out
266
                       // a==out => a!=b
267
268
            var      a1=a.x1,  a2=a.x2,  a3=a.x3;
269
            out.x1 = a1*b.x1 + a2*b.y1 + a3*b.z1;
270
            out.x2 = a1*b.x2 + a2*b.y2 + a3*b.z2;
271
            out.x3 = a1*b.x3 + a2*b.y3 + a3*b.z3;
272
273
                     a1=a.y1,  a2=a.y2,  a3=a.y3;
274
            out.y1 = a1*b.x1 + a2*b.y1 + a3*b.z1;
275
            out.y2 = a1*b.x2 + a2*b.y2 + a3*b.z2;
276
            out.y3 = a1*b.x3 + a2*b.y3 + a3*b.z3;
277
278
                     a1=a.z1,  a2=a.z2,  a3=a.z3;
279
            out.z1 = a1*b.x1 + a2*b.y1 + a3*b.z1;
280
            out.z2 = a1*b.x2 + a2*b.y2 + a3*b.z2;
281
            out.z3 = a1*b.x3 + a2*b.y3 + a3*b.z3;
282
283
            return out;
284
        } else if(a !== b){ // a!=out
285
            return M3_2.mul_b(a,b, out);
286
        } else { // a==out==b
287
            return M3_2.mul_a(a,M3_2.newClone(a), a); //or M3_2.setCopy(M3_2.mul_a(a,a, {}), a)  - need to bench
288
        }
289
    },
290
    mul_b: function(a,b, out){
291
        // hint for optimizing compiler about aliasing (pointer aliasing)
292
        // https://en.wikipedia.org/wiki/Aliasing_(computing)?oldid=931708672#Conflicts_with_optimization
293
        if(a !== out){ // b==a   => b!=out
294
                       // b==out => b!=a
295
296
            var      bx=b.x1,  by=b.y1,  bz=b.z1;
297
            out.x1 = bx*a.x1 + by*a.x2 + bz*a.x3;
298
            out.y1 = bx*a.y1 + by*a.y2 + bz*a.y3;
299
            out.z1 = bx*a.z1 + by*a.z2 + bz*a.z3;
300
301
                     bx=b.x2,  by=b.y2,  bz=b.z2;
302
            out.x2 = bx*a.x1 + by*a.x2 + bz*a.x3;
303
            out.y2 = bx*a.y1 + by*a.y2 + bz*a.y3;
304
            out.z2 = bx*a.z1 + by*a.z2 + bz*a.z3;
305
306
                     bx=b.x3,  by=b.y3,  bz=b.z3;
307
            out.x3 = bx*a.x1 + by*a.x2 + bz*a.x3;
308
            out.y3 = bx*a.y1 + by*a.y2 + bz*a.y3;
309
            out.z3 = bx*a.z1 + by*a.z2 + bz*a.z3;
310
311
            return out;
312
        } else if(b !== a){ // b!=out
313
            return M3_2.mul_a(a,b, out);
314
        } else { // a==out==b
315
            return M3_2.mul_a(a,M3_2.newClone(a), a); //or M3_2.setCopy(M3_2.mul_a(a,a, {}), a)  - need to bench
316
        }
317
    }
318
};
319
320
// var prevent_dead_code_elimination   = 0.0;
321
window.prevent_dead_code_elimination_0 = 0.0;
322
window.prevent_dead_code_elimination_1 = 0.0;
323
window.prevent_dead_code_elimination_2 = 0.0;
324
</script>
Tests:
  • M3_0

     
        var a = M3_0.newVal(
             7., 9., 3.,
             5.,-8., 5.,
            -8.,-8.,-5.);
        var b = M3_0.newIdentity();
        var c = M3_0.newClone(a);
        
        M3_0.mul_a(a,b, a);
        M3_0.setVal(b,
             0.,-5., 1.,
            -8., 5.,-3.,
            -5.,-8., 6.);
        M3_0.mul_a(c,b, c);
        M3_0.mul_a(a,c, b);
        
        M3_0.setVal(a,
            -1.,-6., 0.,
             0., 5., 5.,
             0., 5., 2.);
        M3_0.mul_a(b,a, c);
        
        M3_0.setCopy(b, a);
        M3_0.mul_a(b,c, b);
        M3_0.mul_a(c,a, c);
        
        M3_0.mul_a(a,c, a);
        M3_0.mul_a(b,a, b);
        
        M3_0.mul_a(a,b, c);
        M3_0.mul_a(c,c, a);
        M3_0.setCopy(a, c);
        M3_0.setCopy(a, b);
        M3_0.mul_a(c,b, a);
        
        M3_0.setVal(c,
             1.,-3.,-3.,
             2., 0., 2.,
            -4., 7.,-8.);
        M3_0.mul_a(b,c, b);
        M3_0.mul_a(a,b, a);
        
        window.prevent_dead_code_elimination_0 += +a.x1-a.x2+a.x3 -a.y1+a.y2-a.y3 +a.z1-a.z2+a.z3;
  • M3_1

     
        var a = new M3_1(
             7., 9., 3.,
             5.,-8., 5.,
            -8.,-8.,-5.);
        var b = M3_1.newIdentity();
        var c = M3_1.newClone(a);
        
        M3_1.mul_a(a,b, a);
        M3_1.setVal(b,
             0.,-5., 1.,
            -8., 5.,-3.,
            -5.,-8., 6.);
        M3_1.mul_a(c,b, c);
        M3_1.mul_a(a,c, b);
        
        M3_1.setVal(a,
            -1.,-6., 0.,
             0., 5., 5.,
             0., 5., 2.);
        M3_1.mul_a(b,a, c);
        
        M3_1.setCopy(b, a);
        M3_1.mul_a(b,c, b);
        M3_1.mul_a(c,a, c);
        
        M3_1.mul_a(a,c, a);
        M3_1.mul_a(b,a, b);
        
        M3_1.mul_a(a,b, c);
        M3_1.mul_a(c,c, a);
        M3_1.setCopy(a, c);
        M3_1.setCopy(a, b);
        M3_1.mul_a(c,b, a);
        
        M3_1.setVal(c,
             1.,-3.,-3.,
             2., 0., 2.,
            -4., 7.,-8.);
        M3_1.mul_a(b,c, b);
        M3_1.mul_a(a,b, a);
        
        window.prevent_dead_code_elimination_1 += +a.x1-a.x2+a.x3 -a.y1+a.y2-a.y3 +a.z1-a.z2+a.z3;
  • M3_2

     
        var a = M3_2.newVal(
             7., 9., 3.,
             5.,-8., 5.,
            -8.,-8.,-5.);
        var b = M3_2.newIdentity();
        var c = M3_2.newClone(a);
        
        M3_2.mul_a(a,b, a);
        M3_2.setVal(b,
             0.,-5., 1.,
            -8., 5.,-3.,
            -5.,-8., 6.);
        M3_2.mul_a(c,b, c);
        M3_2.mul_a(a,c, b);
        
        M3_2.setVal(a,
            -1.,-6., 0.,
             0., 5., 5.,
             0., 5., 2.);
        M3_2.mul_a(b,a, c);
        
        M3_2.setCopy(b, a);
        M3_2.mul_a(b,c, b);
        M3_2.mul_a(c,a, c);
        
        M3_2.mul_a(a,c, a);
        M3_2.mul_a(b,a, b);
        
        M3_2.mul_a(a,b, c);
        M3_2.mul_a(c,c, a);
        M3_2.setCopy(a, c);
        M3_2.setCopy(a, b);
        M3_2.mul_a(c,b, a);
        
        M3_2.setVal(c,
             1.,-3.,-3.,
             2., 0., 2.,
            -4., 7.,-8.);
        M3_2.mul_a(b,c, b);
        M3_2.mul_a(a,b, a);
        
        window.prevent_dead_code_elimination_2 += +a.x1-a.x2+a.x3 -a.y1+a.y2-a.y3 +a.z1-a.z2+a.z3;
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    M3_0
    M3_1
    M3_2

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 5 years ago)
Mozilla/5.0 (compatible; MSIE 9.0; ReactOS; Win64; x64) Opera 12.18
Opera 12 on Other
View result in a separate tab
Test name Executions per second
M3_0 45042.2 Ops/sec
M3_1 140091.7 Ops/sec
M3_2 58830.5 Ops/sec