Skip to content

Instantly share code, notes, and snippets.

@culurciello
Last active November 23, 2016 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save culurciello/ac9307197db6f451c19bfb726a35f448 to your computer and use it in GitHub Desktop.
Save culurciello/ac9307197db6f451c19bfb726a35f448 to your computer and use it in GitHub Desktop.
-- E. Culurciello, November 2016
-- test to see if table insert/remove is slower than table addressing
iters = 1e5
tablesize = 1e4
tab1={}
item = torch.randn(iters,1024)
sys.tic()
for i=1,iters do
if i>tablesize then table.remove(tab1,1) end
table.insert(tab1, item[i]:clone())
end
print('table insert', sys.toc())
tabIdx = 1
sys.tic()
for i=1,iters do
tab1[tabIdx%tablesize+1] = item[i]:clone()
tabIdx = tabIdx + 1
end
print('table address', sys.toc())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment