from StringIO import StringIO import logging import subprocess import sys logging.basicConfig() # Compile nbt.pyx before importing subprocess.check_call([sys.executable, "setup_mceditlib.py", "build_ext", "-i", "-f"]) __author__ = 'Rio' import mceditlib.nbt as nbt from timeit import timeit path = "test_files/TileTicks.nbt" test_data = file(path, "rb").read() def load_file(): global test_file test_file = nbt.load(buf=test_data) def save_file(): global resaved_test_file s = StringIO() resaved_test_file = test_file.save(compressed=False) #resaved_test_file = test_file.save(buf=s) #resaved_test_file = s.getvalue() print "File: ", path print "Load: %0.1f ms" % (timeit(load_file, number=1)*1000) print "Save: %0.1f ms" % (timeit(save_file, number=1)*1000) print "Length: ", len(resaved_test_file) assert test_data == resaved_test_file __author__ = 'Rio'