Editing Indexed localStorageDB This edit will create a new revision. Your details (optional) Name Email (won’t be displayed; might be used for Gravatar) URL Test case details Title * Published (uncheck if you want to fiddle around before making the page public) Description (in case you feel further explanation is needed)(Markdown syntax is allowed) Index performance test for https://github.com/vshjxyz/Indexed-localStorageDB to compare the speed with/without indexes Are you a spammer? (just answer the question) Preparation code Preparation code HTML (this will be inserted in the <body> of a valid HTML5 document in standards mode) (useful when testing DOM operations or including libraries) <script src="https://raw.github.com/vshjxyz/Indexed-localStorageDB/master/localstoragedb.js"> </script> Include JavaScript libraries as follows: <script src="//cdn.ext/library.js"></script> Define setup for all tests (variables, functions, arrays or other objects that will be used in the tests) (runs before each clocked test loop, outside of the timed code region) (e.g. define local test variables, reset global variables, clear canvas, etc.) (see FAQ) var lib = new localStorageDB("library"); var index_lib = new localStorageDB("library_indexed"); function rand (min, max) { // http://kevin.vanzonneveld.net // + original by: Leslie Hoare // + bugfixed by: Onno Marsman // % note 1: See the commented out code below for a version which will work with our experimental (though probably unnecessary) srand() function) // * example 1: rand(1, 1); // * returns 1: 1 var argc = arguments.length; if (argc === 0) { min = 0; max = 2147483647; } else if (argc === 1) { throw new Error('Warning: rand() expects exactly 2 parameters, 1 given'); } return Math.floor(Math.random() * (max - min + 1)) + min; /* // See note above for an explanation of the following alternative code // + reimplemented by: Brett Zamir (http://brett-zamir.me) // - depends on: srand // % note 1: This is a very possibly imperfect adaptation from the PHP source code var rand_seed, ctx, PHP_RAND_MAX=2147483647; // 0x7fffffff if (!this.php_js || this.php_js.rand_seed === undefined) { this.srand(); } rand_seed = this.php_js.rand_seed; var argc = arguments.length; if (argc === 1) { throw new Error('Warning: rand() expects exactly 2 parameters, 1 given'); } var do_rand = function (ctx) { return ((ctx * 1103515245 + 12345) % (PHP_RAND_MAX + 1)); }; var php_rand = function (ctxArg) { // php_rand_r this.php_js.rand_seed = do_rand(ctxArg); return parseInt(this.php_js.rand_seed, 10); }; var number = php_rand(rand_seed); if (argc === 2) { number = min + parseInt(parseFloat(parseFloat(max) - min + 1.0) * (number/(PHP_RAND_MAX + 1.0)), 10); } return number; */ } if (lib.isNew()) { lib.createTable("books", ["id", "title", "author", "year", "copies"]); for (var i = 0; i < 150000; i++) { lib.insert("books", { id: "B00" + i, title: "Phantoms in the brain " + rand(1, 10000), author: "Ramachandran", year: (1999 + i), copies: (10 + i) }); } lib.commit(); } if (index_lib.isNew()) { index_lib.createTable("books", ["id", "title", "author", "year", "copies"], ["id", "year"]); for (var i = 0; i < 150; i++) { index_lib.insert("books", { id: "B00" + i, title: "Phantoms in the brain " + i, author: "Ramachandran", year: (1999 + i), copies: (10 + i) }); } index_lib.commit(); } Define teardown for all tests (runs after each clocked test loop, outside of the timed code region) (see FAQ) lib.drop(); lib.commit(); index_lib.drop(); index_lib.commit(); Code snippets to compare Test 1 Title Async (check if this is an asynchronous test) Code if (lib.query("books", { id: "B00149" }).length > 0) { return; } Test 2 Title Async (check if this is an asynchronous test) Code if (index_lib.query("books", { id: "B00149" }).length > 0) { return; }