Guest User

buffer_test

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