t.lua 663 B

1234567891011121314151617181920212223242526272829303132
  1. --------------------------------------
  2. -- ..
  3. local text
  4. local t = os.clock()
  5. text = ""
  6. for i = 1, 10000 do
  7. text = text .. tostring(i)
  8. end
  9. print("[1] time: " ,os.clock() - t)
  10. --------------------------------------
  11. -- format
  12. local string_format = string.format
  13. t = os.clock()
  14. text = ""
  15. for i = 1, 10000 do
  16. text = string_format("%s%s", text, tostring(i))
  17. end
  18. print("[2] time: " ,os.clock() - t)
  19. --------------------------------------
  20. -- concat
  21. local list = {}
  22. local table_insert = table.insert
  23. t = os.clock()
  24. text = ""
  25. for i = 1, 10000 do
  26. table_insert(list, tostring(i))
  27. end
  28. text = table.concat(list, '')
  29. print("[3] time: " ,os.clock() - t)
  30. os.execute("PAUSE")