lkang2 / glmatrix

Automatically exported from code.google.com/p/glmatrix
0 stars 0 forks source link

Alternative fast method with all vars for each matrix #8

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
about 4 times faster here

Just for fun :) The callback is to compensate for the lack of multiple
return values.

mat4.multiply = function(a00, a01, a02, a03, a10, a11, a12, a13, a20, a21,
a22, a23, a30, a31, a32, a33, b00, b01, b02, b03, b10, b11, b12, b13, b20,
b21, b22, b23, b30, b31, b32, b33, callback) {

    callback(b00 * a00 + b01 * a10 + b02 * a20 + b03 * a30,
    b00 * a01 + b01 * a11 + b02 * a21 + b03 * a31,
    b00 * a02 + b01 * a12 + b02 * a22 + b03 * a32,
    b00 * a03 + b01 * a13 + b02 * a23 + b03 * a33,
    b10 * a00 + b11 * a10 + b12 * a20 + b13 * a30,
    b10 * a01 + b11 * a11 + b12 * a21 + b13 * a31,
    b10 * a02 + b11 * a12 + b12 * a22 + b13 * a32,
    b10 * a03 + b11 * a13 + b12 * a23 + b13 * a33,
    b20 * a00 + b21 * a10 + b22 * a20 + b23 * a30,
    b20 * a01 + b21 * a11 + b22 * a21 + b23 * a31,
    b20 * a02 + b21 * a12 + b22 * a22 + b23 * a32,
    b20 * a03 + b21 * a13 + b22 * a23 + b23 * a33,
    b30 * a00 + b31 * a10 + b32 * a20 + b33 * a30,
    b30 * a01 + b31 * a11 + b32 * a21 + b33 * a31,
    b30 * a02 + b31 * a12 + b32 * a22 + b33 * a32,
    b30 * a03 + b31 * a13 + b32 * a23 + b33 * a33);
};

benchmark:

                { name: 'glMatrix', test: function(count) {
                        var a = 5.0;var b = 1.0;var c = 2.0;var d = 4.0;var e = 5.0;var f =
6.0;var g = 2.0;var h = 0.0;var i = 8.0;var j = 10.0;var k = 2.0;var l =
3.0;var m = 4.0;var n = 5.0;var o = 6.0;var p = 7.0;var q = 8.0;var r =
9.0;var s = 10.0;var t = 2.0;var u = 3.0;var v = 4.0;var w = 5.0;var x =
6.0;var y = 7.0;var z = 2.0;var A = 3.0;var B = 4.0;var C = 5.0;var D =
6.0;var E = 7.0;var F = 2.0;
                        function cb(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s,
t, u, v, w, x, y, z, A, B, C, D, E, F){}
                        var start = Date.now();
                        for (var i = 0; i < count; ++i) {
                            mat4.multiply(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r,
s, t, u, v, w, x, y, z, A, B, C, D, E, F, cb);
                        }

                        return Date.now()-start;
                    }},

Original issue reported on code.google.com by danielhe...@gmail.com on 5 Jun 2010 at 8:47

GoogleCodeExporter commented 8 years ago
how would you call two multiply functions after each other ??

Original comment by jeroom832@gmail.com on 6 Jun 2010 at 8:51

GoogleCodeExporter commented 8 years ago
It is just a joke. But I don't understand your question. You could easely do:
mat4.multiply(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r,
s, t, u, v, w, x, y, z, A, B, C, D, E, F, cb);
mat4.multiply(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r,
s, t, u, v, w, x, y, z, A, B, C, D, E, F, cb);

(cb is called before mat4.multiply returns)

Original comment by danielhe...@gmail.com on 6 Jun 2010 at 10:46

GoogleCodeExporter commented 8 years ago
my mistake, I was thinking of something that wasn't correct

Original comment by jeroom832@gmail.com on 6 Jun 2010 at 11:10

GoogleCodeExporter commented 8 years ago
As much as I appreciate the programmer humor (my goodness, we're willing to do 
anything 
for a couple of clock cycles, aren't we?) This shouldn't be listed as a defect.

Original comment by Tojiro@gmail.com on 7 Jun 2010 at 3:13