Skip to content

Instantly share code, notes, and snippets.

@arantius
Last active December 27, 2015 04:29
Show Gist options
  • Save arantius/7267388 to your computer and use it in GitHub Desktop.
Save arantius/7267388 to your computer and use it in GitHub Desktop.
User script benchmark for GM_getValue() and GM_setValue().
// ==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));
}
@BhavukMathur
Copy link

Hello Sir, I copied this code in a Greasemonkey script. Can you please tell me how to see the result of this script. I'm not getting any result on loading the web-page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment