Skip to content

Instantly share code, notes, and snippets.

@pudov
Last active February 22, 2016 20:27
Show Gist options
  • Select an option

  • Save pudov/c746b7abfc8bc4e96b74 to your computer and use it in GitHub Desktop.

Select an option

Save pudov/c746b7abfc8bc4e96b74 to your computer and use it in GitHub Desktop.
from random import sample
from time import time
def buble_sort(a):
for i in xrange(len(a)):
for j in xrange(1, len(a) - i):
if a[j-1] > a[j]:
temp = a[j]
a[j] = a[j-1]
a[j-1] = temp
l = sample(xrange(10000000), 10000)
s = time()
buble_sort(l)
e = time()
print "took:", (e-s), "seconds"
@pudov
Copy link
Copy Markdown
Author

pudov commented Feb 22, 2016

python bubble.py
took: 9.38592505455 seconds

@pudov
Copy link
Copy Markdown
Author

pudov commented Feb 22, 2016

pypy bubble.py
took: 0.678442001343 seconds

@pudov
Copy link
Copy Markdown
Author

pudov commented Feb 22, 2016

g++ -O2 -std=c++11 bubble.cpp && ./a.out
took: 335.981 ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment