Skip to content

Commit

Permalink
Working on profiling.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwasham committed Aug 9, 2016
1 parent 4b748b9 commit 68f26f3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions interview/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
numbers.txt
out.txt
2 changes: 1 addition & 1 deletion interview/generate_numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def main():
numbers = random.sample(range(9999999), 100)
numbers = random.sample(range(9999999), 1000000)
open("numbers.txt", "w")\
.write("\n".join(str(n) for n in numbers))

Expand Down
5 changes: 4 additions & 1 deletion interview/sorting_linear.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""
Task:
Implement an algorithm to sort 1,000,000 32-bit integers, using only 350K of memory.
The numbers could be any number from 0 to 9,999,999
The numbers are in a file, one line per number. There are no duplicates.
Expand Down Expand Up @@ -31,14 +33,15 @@ def get_sorted_numbers(self):
yield base + j


@profile
def main():
bitsorter = Bitsort(9999999)

with open("numbers.txt", "r") as in_file:
for line in in_file:
bitsorter.save_number(int(line.rstrip()))

out_file = open("out.txt", "w")
out_file = open("out.txt", "w", 4096)
for number in bitsorter.get_sorted_numbers():
out_file.write(str(number) + "\n")

Expand Down

0 comments on commit 68f26f3

Please sign in to comment.