Skip to content

Instantly share code, notes, and snippets.

@preshing
Created November 5, 2012 02:54
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 preshing/4015054 to your computer and use it in GitHub Desktop.
Save preshing/4015054 to your computer and use it in GitHub Desktop.
Python script to help validate 1MB Sorter
from subprocess import *
import time
def validate(sequence):
start = time.clock()
sorter = Popen('sort1mb.exe', stdin=PIPE, stdout=PIPE, stderr=PIPE)
for value in sequence:
sorter.stdin.write('%08d\n' % value)
sorter.stdin.close()
result = [int(line) for line in sorter.stdout]
interval = time.clock() - start
if result == sorted(sequence):
print('Result OK after %.03f secs' % interval)
print(sorter.stderr.readline().strip())
else:
print('***ERROR*** after %.03f secs' % interval)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment