import sys, time def heapsort(list, comparison=lambda x, y: x < y): start = len(list) // 2 - 1 while start >= 0: _heapsort_sift(list, comparison, start, len(list)) start = start - 1 end = len(list) - 1 while end > 0: t = list[0] list[0] = list[end] list[end] = t _heapsort_sift(list, comparison, 0, end) end = end - 1 def _heapsort_sift(list, comparison, start, count): while 1: child = start * 2 + 1 if child >= count: break if child < count - 1 and comparison(list[child], list[child + 1]): child += 1 if comparison(list[start], list[child]): t = list[start] list[start] = list[child] list[child] = t start = child else: return f = open(sys.argv[1], "r") d = [x.strip() for x in f.readlines()] t = time.time() heapsort(d) print time.time() - t #print d