import timing
import time
import sys
from random import *

###### bubblesort

def bubble(A):
    n = len(A)
    i, j = 0,0
    while i<n-1-i:  # note n-1, not n
        j = 0
        while j<n-1:
            if A[j]>A[j+1]:
                A[j],A[j+1] = A[j+1],A[j]    # swap
            j +=1
        # while j
        # print A  # trace
        i +=1
    # while i

#### function to generate random array of doubles of size n:
def randarr(n):
    A = [0]*n
    i = 0
    while i<n:
        A[i] = random()
        i +=1
    #while
    return A


if len(sys.argv)>1:
    size = int(sys.argv[1])  # size of test array as command-line argument
else: size = 2000

A = randarr(size)

timing.start()
bubble(A)
timing.finish()

m1 = timing.milli()

print "time to sort:",m1,"ms"

