Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --!native
- numbers = {}
- dictionary = {}
- for i=1,1e7 do
- numbers[#numbers+1] = true
- dictionary[tostring(i)] = true
- end
- local iterator = function(tbl, index)
- local nextIndex = index + 1
- local v = tbl[nextIndex]
- if v ~= nil then
- return nextIndex, v
- end
- end
- local numbers = setmetatable(numbers, {
- __iter = function(tbl)
- return iterator, tbl, 0
- end,
- })
- local dictionary = setmetatable(numbers, {
- __iter = function(tbl)
- return next, tbl, nil
- end,
- })
- task.wait()
- --ipairs numbers
- local t = os.clock()
- local value = true
- for i,v in ipairs(numbers) do
- value = value and v --you need to do something otherwise it won't be a meaningful test
- end
- local dt_ipairs_list = os.clock() - t
- task.wait()
- --pairs numbers
- local t = os.clock()
- local value = true
- for i,v in pairs(numbers) do
- value = value and v --you need to do something otherwise it won't be a meaningful test
- end
- local dt_pairs_list = os.clock() - t
- task.wait()
- --pairs dictionary
- local t = os.clock()
- local value = true
- for i,v in pairs(dictionary) do
- value = value and v --you need to do something otherwise it won't be a meaningful test
- end
- local dt_pairs_dict = os.clock() - t
- task.wait()
- --no pairs numbers
- local t = os.clock()
- local value = true
- for i,v in numbers do
- value = value and v --you need to do something otherwise it won't be a meaningful test
- end
- local dt_nopairs_list = os.clock() - t
- task.wait()
- --no pairs dictionary
- local t = os.clock()
- local value = true
- for i,v in dictionary do
- value = value and v --you need to do something otherwise it won't be a meaningful test
- end
- local dt_nopairs_dict = os.clock() - t
- task.wait()
- print("ipairs list: "..dt_ipairs_list)
- print("pairs list: "..dt_pairs_list)
- print("pairs dict: "..dt_pairs_dict)
- print("nopairs list: "..dt_nopairs_list)
- print("nopairs dict: "..dt_nopairs_dict)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement