Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local x,y = term.getSize()
- os.loadAPI("api/buffer")
- test = buffer
- --local test = term_buffer
- local trials = ... and ... or 10
- local tstart,tend,tstart_buffer,tend_buffer = 0
- term.clear()
- --start benchmark of regular term api
- tstart = os.clock()
- for trial=trials,0,-1 do
- term.setCursorPos(1,1)
- for j=0,y do
- for i=0,x do
- term.setCursorPos(i,j)
- term.setBackgroundColor((2^math.random(0,15)))
- term.setTextColor((2^math.random(0,15)))
- term.write(tostring(math.random(0,10)))
- end
- end
- end
- tend = os.clock()
- sleep(.2)
- term.clear()
- --start benchmark of buffer api
- tstart_buffer = os.clock()
- for trial=trials,0,-1 do
- test.pos_x = 1
- test.pos_y = 1
- for j=0,y do
- for i=0,x do
- test.pos_x = i
- test.pos_y = j
- test.back = (2^math.random(0,15))
- test.text = (2^math.random(0,15))
- test:write(tostring(math.random(0,10)))
- end
- end
- test:draw()
- end
- tend_buffer = os.clock()
- --done with generation
- sleep(.2)
- term.setCursorPos(1,1)
- term.setBackgroundColor(0x8000)
- term.setTextColor(0x1)
- term.clear()
- term.write("Trials: "..(trials).." Unbuff: "..(tend-tstart).." buff: "..(tend_buffer-tstart_buffer).." diff: "..(math.abs((tend-tstart)-(tend_buffer-tstart_buffer))))
- term.setCursorPos(1,2)
Advertisement
Add Comment
Please, Sign In to add comment