michael@0: // |reftest| random -- BigO michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: var BUGNUMBER = 416628; michael@0: var summary = 'O(n^2) blowup due to overlong cx->tempPool arena list'; michael@0: var actual = ''; michael@0: var expect = ''; michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: test(); michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: function test() michael@0: { michael@0: enterFunc ('test'); michael@0: printBugNumber(BUGNUMBER); michael@0: printStatus (summary); michael@0: michael@0: var data = {X:[], Y:[]}; michael@0: michael@0: Function.prototype.inherits = function(parentCtor) { michael@0: moo_inherits(this, parentCtor); michael@0: }; michael@0: michael@0: moo_inherits = function(childCtor, parentCtor) { michael@0: /** @constructor */ michael@0: function tempCtor() {}; michael@0: tempCtor.prototype = parentCtor.prototype; michael@0: childCtor.superClass_ = parentCtor.prototype; michael@0: childCtor.prototype = new tempCtor(); michael@0: childCtor.prototype.constructor = childCtor; michael@0: }; michael@0: michael@0: var jstart = 100; michael@0: var jstop = 1000; michael@0: var jinterval = (jstop - jstart)/9; michael@0: michael@0: if (true) { michael@0: for (var j = jstart; j < jstop; j += jinterval) michael@0: { michael@0: data.X.push(j); michael@0: var code = ''; michael@0: for (var i = 0; i < j; i++) michael@0: { michael@0: code += createCode(i); michael@0: } michael@0: gc(); michael@0: var start = new Date(); michael@0: eval(code); michael@0: var stop = new Date(); michael@0: data.Y.push(stop - start); michael@0: } michael@0: } michael@0: michael@0: var order = BigO(data); michael@0: michael@0: var msg = ''; michael@0: for (var p = 0; p < data.X.length; p++) michael@0: { michael@0: msg += '(' + data.X[p] + ', ' + data.Y[p] + '); '; michael@0: } michael@0: printStatus(msg); michael@0: printStatus('Order: ' + order); michael@0: michael@0: reportCompare(true, order < 2, 'BigO ' + order + ' < 2'); michael@0: michael@0: exitFunc ('test'); michael@0: } michael@0: michael@0: function createCode(i) michael@0: { michael@0: var code = ''; michael@0: michael@0: code += "var str1_" + i + "='This is 1 a test " + i + " string.';"; michael@0: code += "var str2_" + i + "='This is 2 a test " + i + " string.';"; michael@0: code += "var str3_" + i + "='This is 3 a test " + i + " string.';"; michael@0: code += "var str4_" + i + "='This is 4 a test " + i + " string.';"; michael@0: code += "var str5_" + i + "='This is 5 a test " + i + " string.';"; michael@0: code += "var str6_" + i + "='This is 6 a test " + i + " string.';"; michael@0: code += "var str7_" + i + "='This is 7 a test " + i + " string.';"; michael@0: code += ""; michael@0: code += "var base" + i + " = function() {this.a_=4;this.b_=5};"; michael@0: code += "base" + i + ".f1 = function() {this.a_=4;this.b_=5};"; michael@0: code += "base" + i + ".prototype.f2 = function() {this.a_=4;this.b_=5};"; michael@0: code += "base" + i + ".prototype.f3 = function() {this.a_=4;this.b_=5};"; michael@0: code += "base" + i + ".prototype.f4 = function() {this.a_=4;this.b_=5};"; michael@0: code += "base" + i + ".prototype.f5 = function() {this.a_=4;this.b_=5};"; michael@0: code += ""; michael@0: code += "var child" + i + " = function() {this.a_=4;this.b_=5};"; michael@0: code += "child" + i + ".inherits(base" + i + ");"; michael@0: code += "child" + i + ".f1 = function() {this.a_=4;this.b_=5};"; michael@0: code += "child" + i + ".prototype.f2 = function() {this.a_=4;this.b_=5};"; michael@0: code += "child" + i + ".prototype.f3 = function() {this.a_=4;this.b_=5};"; michael@0: code += "child" + i + ".prototype.f4 = function() {this.a_=4;this.b_=5};"; michael@0: code += "child" + i + ".prototype.f5 = function() {this.a_=4;this.b_=5};"; michael@0: code += ""; michael@0: code += "var gchild" + i + " = function() {this.a_=4;this.b_=5};"; michael@0: code += "gchild" + i + ".inherits(child" + i + ");"; michael@0: code += "gchild" + i + ".f1 = function() {this.a_=4;this.b_=5};"; michael@0: code += "gchild" + i + ".prototype.f2 = function() {this.a_=4;this.b_=5};"; michael@0: code += "gchild" + i + ".prototype.f3 = function() {this.a_=4;this.b_=5};"; michael@0: code += "gchild" + i + ".prototype.f4 = function() {this.a_=4;this.b_=5};"; michael@0: code += "gchild" + i + ".prototype.f5 = function() {this.a_=4;this.b_=5};"; michael@0: michael@0: return code; michael@0: }