import timer in-place stacksy append(xgeneral function timer utility rept from sys import argv pushespopsitems (int(argfor arg in argv[ :]def stackops(stackclass) stackclass('spam'for in range(pushes) push(ifor in range(items) [ifor in range(pops) pop(make stack object exercise its methods xrange generator or mod __import__(nfor mod in (stack stack stack )rept*(push+pop+ixprint('% :mod __name__end='print(timer test(reptstackopsgetattr(mod'stack'))results under python the following are some of the timings reported by the test driver script the three outputs represent the measured run times in seconds for the originaltupleand inplace stacks for each stack typethe first test creates stack objects and performs roughly , stack operations ( repetitions ( pushes indexes pops)in the test duration times listed these results were obtained on fairly slow windows netbook laptop under python as usual for benchmarksyour mileage will probably vary :\pp \dstruct\basicpython stacktime py stack stack stack :\pp \dstruct\basicpython stacktime py stack stack stack :\pp \dstruct\basicpython stacktime py stack stack stack :\pp \dstruct\basicpython stacktime py stack stack stack if you look closely enoughyou'll notice that the results show that the tuple-based stack (stack performs better when we do more pushing and poppingbut worse if we do much indexing indexing lists is extremely fast for built-in lists (stack and stack )but very slow for tuple trees--the python class must traverse the tree manually data structures