def run(param_file, problem): probInfos = problem.split('-') listSpecIndex = int(probInfos[0]) if len(probInfos) > 1: listLength = int(probInfos[1]) else: listLength = 4000 if len(probInfos) > 2: numberOfRepeat = int(probInfos[2]) else: numberOfRepeat = 1 if len(probInfos) > 3: groupSize = int(probInfos[3]) else: groupSize = 1 params = read_params_from_file(param_file) if int(params['nothing']) != 0: return {'TIME': float("inf")} coopTreeFactory = CooperationTreeFactory(name="test factory") try: treeEncodedNumber = int(params['coopTree']) except: treeEncodedNumber = int(float(params['coopTree'])) createTree = coopTreeFactory.createTreeFromEncodedNumber coopTree = createTree(name='coop tree', encodedNumber=treeEncodedNumber, radix=6) l = [] for g in range(groupSize): l.append(create_test_list(listSpecs[listSpecIndex], listLength, 0)) meanTime = 0.0 for r in range(numberOfRepeat): sortingTime = 0.0 for i in range(groupSize): l1 = list(l[i]) tb = benchmarkTime() try: l1 = coopsort(l1, coopTree.getRoot()) except: return {'TIME': float("inf")} te = benchmarkTime() sortingTime = sortingTime + (te - tb) del l1[:] del l1 meanTime = meanTime + sortingTime measures = {'TIME': meanTime / numberOfRepeat} return measures
def run(param_file, problem): N = int(problem) params = read_params_from_file(param_file) if int(params['nothing']) != 0: return {'TIME': float("inf")} #print params coopTreeFactory = CooperationTreeFactory(name="test factory") coopTree = coopTreeFactory.createTreeFromEncodedNumber(name='coop tree', encodedNumber=int(params['coopTree'])) #print coopTree l = [int(N * random.random()) for i in xrange(N)] t = time.clock() l = coopsort(l, coopTree.getRoot()) measures = {'TIME': time.clock() - t} return measures
# Time. #for fcn in fcns: coopTreeFactory = CooperationTreeFactory(name="test factory") coopTrees = {} coopTrees["quick sort"] = coopTreeFactory.createTree(name="quick sort", methodSequence=[2]) coopTrees["merge sort"] = coopTreeFactory.createTreeFromEncodedNumber( name="merge sort", encodedNumber=1) coopTrees["insertion sort"] = coopTreeFactory.createTree(name="insertion sort", methodSequence=[0]) coopTrees["radix sort"] = coopTreeFactory.createTree(name="radix sort", methodSequence=[3]) coopTrees['coop sort 1'] = coopTreeFactory.createTree(name='test tree 1', methodSequence=[4, 2, 3]) coopTrees['coop sort 2'] = coopTreeFactory.createTree( name='test tree 2', methodSequence=[4, 4, 2, 3, 3]) coopTrees['coop sort 3'] = coopTreeFactory.createTreeFromEncodedNumber( name='test tree 3', encodedNumber=45203) for name, coopTree in coopTrees.iteritems(): l = [int(N * random.random()) for i in xrange(N)] print "CoopSort with the tree:", coopTree._name t = time.clock() l = coopsort(l, coopTree.getRoot()) t = time.clock() - t #print "after sorting", l print 'Computing time: %6.2f second \n' % (t)
profiles[name] = [] for i in range(numberOfList): l = create_test_list(listSpec, listLength, 0) minTime = float('inf') cpuTime = {} for name, coopTree in coopTrees.iteritems(): meanTime = 0.0 for r in range(numberOfRepeat): l1 = list(l) if isfunction(coopTree): tb = benchmarkTime() l1 = coopTree(l1) else: tb = benchmarkTime() l1 = coopsort(l1, coopTree.getRoot()) te = benchmarkTime() del l1[:] del l1 meanTime = meanTime + (te - tb) meanTime = meanTime / numberOfRepeat cpuTime[name] = meanTime if (meanTime < minTime): minTime = meanTime for name, t in cpuTime.iteritems(): profiles[name].append(t / minTime) percentage = [float(i + 1) / numberOfList for i in range(numberOfList)] for name, x in profiles.iteritems():
# Time. #for fcn in fcns: coopTreeFactory = CooperationTreeFactory(name="test factory") coopTrees = {} coopTrees["quick sort"] = coopTreeFactory.createTree(name="quick sort", methodSequence=[2]) coopTrees["merge sort"] = coopTreeFactory.createTreeFromEncodedNumber(name="merge sort", encodedNumber=1) coopTrees["insertion sort"] = coopTreeFactory.createTree(name="insertion sort", methodSequence=[0]) coopTrees["radix sort"] = coopTreeFactory.createTree(name="radix sort", methodSequence=[3]) coopTrees['coop sort 1'] = coopTreeFactory.createTree(name='test tree 1', methodSequence=[4,2,3]) coopTrees['coop sort 2'] = coopTreeFactory.createTree(name='test tree 2', methodSequence=[4,4,2,3,3]) coopTrees['coop sort 3'] = coopTreeFactory.createTreeFromEncodedNumber(name='test tree 3', encodedNumber=45203) for name, coopTree in coopTrees.iteritems(): l = [int(N * random.random()) for i in xrange(N)] print "CoopSort with the tree:", coopTree._name t = time.clock() l = coopsort(l, coopTree.getRoot()) t = time.clock() - t #print "after sorting", l print 'Computing time: %6.2f second \n' % (t)
numberOfRepeat = benchmarkSpec['testing']['repeats'] for listSpec in listSpecs: listType = str(listSpec) cpuTime[listType] = {} for name, coopTree in coopTrees.iteritems(): cpuTime[listType][name] = {} for k in range(numberOfList): n = listLengthUnit * (k + 1) l = create_test_list(listSpec, n, 0) for name, coopTree in coopTrees.iteritems(): meanTime = 0.0 for r in range(numberOfRepeat): l1 = list(l) if isfunction(coopTree): tb = benchmarkTime() l1 = coopTree(l1) else: tb = benchmarkTime() l1 = coopsort(l1, coopTree.getRoot()) te = benchmarkTime() listIsSorted = verify_sorted_list(l1) if listIsSorted: meanTime = meanTime + (te - tb) else: raise Exception("There is a problem with " + name) del l1[:] del l1 cpuTime[listType][name][n] = meanTime / numberOfRepeat print cpuTime