Skip to content

Instantly share code, notes, and snippets.

@tzarskyz
Forked from arantius/gist:7267388
Last active August 29, 2015 13:57
Show Gist options
  • Save tzarskyz/9372483 to your computer and use it in GitHub Desktop.
Save tzarskyz/9372483 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Benchmark: getValue/setValue
// @namespace test
// @include http*
// @version 1
// @grant GM_getValue
// @grant GM_setValue
// ==/UserScript==
var iters = 40;
if (window === top) {
console.log('Starting set benchmark ...');
var start = new Date().valueOf();
for (var i = 0; i < iters;) {
GM_setValue('i', i++); GM_setValue('i', i++);
GM_setValue('i', i++); GM_setValue('i', i++);
GM_setValue('i', i++); GM_setValue('i', i++);
GM_setValue('i', i++); GM_setValue('i', i++);
GM_setValue('i', i++); GM_setValue('i', i++);
}
var end = new Date().valueOf();
console.log(i, 'set calls took', (end - start));
console.log('Starting get benchmark ...');
var start = new Date().valueOf();
for (var i = 0; i < iters; i+=10) {
GM_getValue('i'); GM_getValue('i');
GM_getValue('i'); GM_getValue('i');
GM_getValue('i'); GM_getValue('i');
GM_getValue('i'); GM_getValue('i');
GM_getValue('i'); GM_getValue('i');
}
var end = new Date().valueOf();
console.log(i, 'get calls took', (end - start));
console.log('Starting get/set benchmark ...');
var start = new Date().valueOf();
for (var i = 0; i < iters; ) {
GM_getValue('i'); GM_setValue('i', i++);
GM_getValue('i'); GM_setValue('i', i++);
GM_getValue('i'); GM_setValue('i', i++);
GM_getValue('i'); GM_setValue('i', i++);
GM_getValue('i'); GM_setValue('i', i++);
GM_getValue('i'); GM_setValue('i', i++);
GM_getValue('i'); GM_setValue('i', i++);
GM_getValue('i'); GM_setValue('i', i++);
GM_getValue('i'); GM_setValue('i', i++);
GM_getValue('i'); GM_setValue('i', i++);
}
var end = new Date().valueOf();
console.log(i, 'get/set calls took', (end - start));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment