Created
May 25, 2018 23:31
-
-
Save chearon/d09dceeeca8f8e98e2cff7e4e3ccb10a to your computer and use it in GitHub Desktop.
Revisions
-
chearon created this gist
May 25, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,61 @@ const Vue = require('vue'); bigarray = []; for (let i = 0; i < 30000; ++i) { bigarray.push({a: Math.random(), b: Math.random(), c: Math.random(), d: Math.random(), e: Math.random(), f: Math.random(), g: Math.random(), h: Math.random(), i: Math.random()}); } let freeze = false; /** * Pretend like this is the store */ store = new Vue({ data: {bigarray}, computed: { filtered() { const ret = this.bigarray.filter((item, i) => { item.a; // pretend like we depend item.i; // on some things return i % 2 === 0; }); return freeze ? Object.freeze(ret) : ret; }, } }); function touchArray() { for (const item of bigarray) { item.a = Math.random(); } } function test() { console.time(`freeze=${freeze}`); const vm = new Vue({ props: ["list"], propsData: {list: store.filtered}, computed: { sorted() { return this.list.slice().sort((a, b) => a.i - b.i); } } }); vm.sorted; console.timeEnd(`freeze=${freeze}`); } freeze = true; test(), touchArray(); test(), touchArray(); test(), touchArray(); test(), touchArray(); test(), touchArray(); freeze = false; test(), touchArray(); test(), touchArray(); test(), touchArray(); test(), touchArray(); test(), touchArray();