Last active
December 27, 2015 04:29
-
-
Save arantius/7267388 to your computer and use it in GitHub Desktop.
User script benchmark for GM_getValue() and GM_setValue().
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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
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.