Skip to content

Latest commit

 

History

History
33 lines (24 loc) · 818 Bytes

readme.md

File metadata and controls

33 lines (24 loc) · 818 Bytes

Dependency Status

Split executing of javascript code into slice

Normal Javascript

import slicePerform, {_clock} from '../lib/index'
const COUNT = 10000000


let begin = _clock()
for (var index = 0; index < COUNT; index++);
let duration = _clock() - begin

console.log(index, `${duration / 1000000000}s`)

Slice Javascript

const slicePerform = require('slice-perform')
const COUNT = 10000000

let index = 0
slicePerform(
	90, // sliceTimeInMS
	10, // waitTimeInMS, in wait time, ui thread will not be blocked by javascript
	() => index < COUNT,  // test
	() => index += 1,     // fn
	(duration) => console.log(index, `${duration / 1000000000}s`) // callback
)