 License New BSD license
 Lines 34
##### Keywords bogosort (5) testing (1)
##### Related Bogosort Implementation with Python Numpy BogoSort with std::random_shuffle BogoSort Bogosort Flow Chart Siafoo Users Group
##### Permissions Owner: Theodore Test Viewable by Everyone Editable by All Siafoo Users

# Bogosort Implementation Comparison Testing 0

 In Brief Test a sequence of bogosort functions on a series of scrambled linear arrays of ascending maximum size. Repeat the tests a given number of times and return a 3-d array of timing information.... more
 Language NumPy
# 's
` 1# Importing some sample bogosort implementations downloaded from around Siafoo  ### 2from vanilla_bogosort import bogo_sort as vanilla_bogosort 3from numpy_bogosort import bogosort as numpy_bogosort 4 5# Regular imports 6import numpy 7from time import time 8from random import shuffle 9from pprint import pprint10from random import shuffle1112def test_bogos(sequence_of_bogosort_functions,number_of_tests,maximum_array_size):13    ''' Times a sequences of bogosort functions for a series of increasingly large14    arrays, randomly scrambled, repeated a set number of times.1516    Returns a 3d numpy array containing the time-to-run data for all functions17    Rows are test iterations, columns are array-sizes, and depth corresponds to18    function used.19    '''2021    num_functions = len(sequence_of_bogosort_functions)22    times_array = numpy.atleast_3d(numpy.zeros((number_of_tests,maximum_array_size,num_functions)))2324    for (t_num,s_num,f_num), x in numpy.ndenumerate(times_array):25        26        fun = sequence_of_bogosort_functions[f_num]27        a_list = range(s_num)28        shuffle(a_list)2930        start_time = time()31        sorted_array = fun(a_list)32        end_time = time()3334        times_array[t_num,s_num,f_num] = end_time - start_time3536    return times_array3738if __name__ == '__main__':3940    fun_seq = [vanilla_bogosort,numpy_bogosort]41    num_tests = 100042    max_size = 943    times_arr = test_bogos_02(fun_seq,num_tests,max_size)44    print 'Average Times',times_arr.mean(axis=0)`

Test a sequence of bogosort functions on a series of scrambled linear arrays of ascending maximum size. Repeat the tests a given number of times and return a 3-d array of timing information.

For the main example shown above, I got the following results. They generally demonstrate that the numpy code is faster than the generic python for larger arrays. Surprisingly, the difference was not terribly great. I'd wager that they become more distinct at larger array sizes. Below, the first column is the vanilla python, and the second column is the numpy implementation. The rows correspond to array size, ranging from 0 to 8.

# 's
`1`
Average Times

[[ 5.05232811e-06 2.64606476e-05]

[ 3.69405746e-06 1.90448761e-05]

[ 1.17156506e-05 3.12585831e-05]

[ 4.38842773e-05 6.61971569e-05]

[ 2.15771198e-04 2.37778425e-04]

[ 1.27175498e-03 1.23753619e-03]

[ 8.11699867e-03 7.92551494e-03]

[ 6.16261077e-02 5.91173282e-02]

[ 5.82711076e-01 5.04583259e-01]]