Guest User

buffer_test

a guest
Dec 26th, 2013
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.27 KB | None | 0 0
  1. local x,y = term.getSize()
  2. os.loadAPI("api/buffer")
  3. test = buffer
  4. --local test = term_buffer
  5. local trials = ... and ... or 10
  6. local tstart,tend,tstart_buffer,tend_buffer = 0
  7. term.clear()
  8. --start benchmark of regular term api
  9. tstart = os.clock()
  10. for trial=trials,0,-1 do
  11.   term.setCursorPos(1,1)
  12.   for j=0,y do
  13.     for i=0,x do
  14.       term.setCursorPos(i,j)
  15.       term.setBackgroundColor((2^math.random(0,15)))
  16.       term.setTextColor((2^math.random(0,15)))
  17.       term.write(tostring(math.random(0,10)))
  18.     end
  19.   end
  20. end
  21. tend = os.clock()
  22. sleep(.2)
  23. term.clear()
  24. --start benchmark of buffer api
  25. tstart_buffer = os.clock()
  26. for trial=trials,0,-1 do
  27.   test.pos_x = 1
  28.   test.pos_y = 1
  29.   for j=0,y do
  30.     for i=0,x do
  31.       test.pos_x = i
  32.       test.pos_y = j
  33.       test.back = (2^math.random(0,15))
  34.       test.text = (2^math.random(0,15))
  35.       test:write(tostring(math.random(0,10)))
  36.     end
  37.   end
  38.   test:draw()
  39. end
  40. tend_buffer = os.clock()
  41. --done with generation
  42. sleep(.2)
  43. term.setCursorPos(1,1)
  44. term.setBackgroundColor(0x8000)
  45. term.setTextColor(0x1)
  46. term.clear()
  47. term.write("Trials: "..(trials).." Unbuff: "..(tend-tstart).." buff: "..(tend_buffer-tstart_buffer).." diff: "..(math.abs((tend-tstart)-(tend_buffer-tstart_buffer))))
  48. term.setCursorPos(1,2)
Advertisement
Add Comment
Please, Sign In to add comment