Exemplo n.º 1
0
        return not any(_try_composite(a, d, n, s) for a in (2, 3, 5, 7, 11, 13))
    if n < 341550071728321: 
        return not any(_try_composite(a, d, n, s) for a in (2, 3, 5, 7, 11, 13, 17))
    # otherwise
    return not any(_try_composite(a, d, n, s) 
                   for a in _known_primes[:_precision_for_huge_n])
 

# Measurement and plotting:

START = 30000000
END = 30002000
STRIDE = 1
REPEATS = 1

td_results = T.resource_runtime_plot(trial_division, START, END, STRIDE, REPEATS)
# aks_results = T.resource_runtime_plot(aks, START, END, STRIDE, REPEATS)
mr_results = T.resource_runtime_plot(mr, START, END, STRIDE, REPEATS)

print "average for trial division: ", td_results[2]
# print "average for aks:            ", aks_results[2]
print "average for mr:             ", mr_results[2]

# fig = plt.figure()
# ax1 = fig.add_subplot(211)
# ax1.plot(td_results[0], td_results[1], label="td")
# ax2 = fig.add_subplot(212)
# ax2.plot(aks_results[0], aks_results[1], label="aks")
# ax3 = fig.add_subplot(212)
# ax3.plot(mr_results[0], mr_results[1], label="mr")
# plt.show()
Exemplo n.º 2
0
    line1result, line2result, line3result, line4result, line5result,
    line6result
]

# Test the merge functions

print ""
print "testing merge functions..."

for module in modules:
    for i in range(len(lines)):
        assert module.merge(lines[i]) == results[i]

print "all tests passed"
print "creating test lists..."
the_lists = T.create_lists(list_count, list_size)
print "test lists created"
print "performing time measurements..."

anontimes = T.runtime_lists(Anon.merge, the_lists)
benjamintimes = T.runtime_lists(Benjamin.merge, the_lists)
liyuetimes = T.runtime_lists(LiYue.merge, the_lists)
timtimes = T.runtime_lists(Tim.merge, the_lists)

print ""
print "================="
print "Results:"
print ""
print "Anon total:       " + str(anontimes[0])
print "Anon average:     " + str(anontimes[1])
print ""
Exemplo n.º 3
0
        return not any(
            _try_composite(a, d, n, s) for a in (2, 3, 5, 7, 11, 13, 17))
    # otherwise
    return not any(
        _try_composite(a, d, n, s)
        for a in _known_primes[:_precision_for_huge_n])


# Measurement and plotting:

START = 30000000
END = 30002000
STRIDE = 1
REPEATS = 1

td_results = T.resource_runtime_plot(trial_division, START, END, STRIDE,
                                     REPEATS)
# aks_results = T.resource_runtime_plot(aks, START, END, STRIDE, REPEATS)
mr_results = T.resource_runtime_plot(mr, START, END, STRIDE, REPEATS)

print "average for trial division: ", td_results[2]
# print "average for aks:            ", aks_results[2]
print "average for mr:             ", mr_results[2]

# fig = plt.figure()
# ax1 = fig.add_subplot(211)
# ax1.plot(td_results[0], td_results[1], label="td")
# ax2 = fig.add_subplot(212)
# ax2.plot(aks_results[0], aks_results[1], label="aks")
# ax3 = fig.add_subplot(212)
# ax3.plot(mr_results[0], mr_results[1], label="mr")
# plt.show()
Exemplo n.º 4
0
sys.path.append('../')
import Timeutils as T

sys.setrecursionlimit(1500)

init = 0
end  = 1400
range_repeats = 2
single_repeats = 200

print "\nRuntime for a range of inputs: from {0} to {1}, {2} repeats:".format(init, end, range_repeats)

time_fibR = "Takes too long."
print "Recursive: ", time_fibR

time_fibTR = T.resource_runtime_range(F.fibTR, init, end, range_repeats)[0]
print "Tail Recursive:          ", time_fibTR

time_fibFR = T.resource_runtime_range(F.fibFR, init, end, range_repeats)[0]
print "For loop range():        ", time_fibFR

time_fibFX = T.resource_runtime_range(F.fibFX, init, end, range_repeats)[0]
print "For loop xrange():       ", time_fibFX

time_fibFN = T.resource_runtime_range(F.fibFN, init, end, range_repeats)[0]
print "For loop numpy.arange(): ", time_fibFN

time_fibAnalytic = T.resource_runtime_range(F.fibAnalytic, init, end, range_repeats)[0]
print "Analytic:                ", time_fibAnalytic

time_fibMatrix = T.resource_runtime_range(F.fibMatrix, init, end, range_repeats)[0]
Exemplo n.º 5
0
import Timeutils as T

sys.setrecursionlimit(1500)

init = 0
end = 1400
range_repeats = 2
single_repeats = 200

print "\nRuntime for a range of inputs: from {0} to {1}, {2} repeats:".format(
    init, end, range_repeats)

time_fibR = "Takes too long."
print "Recursive: ", time_fibR

time_fibTR = T.resource_runtime_range(F.fibTR, init, end, range_repeats)[0]
print "Tail Recursive:          ", time_fibTR

time_fibFR = T.resource_runtime_range(F.fibFR, init, end, range_repeats)[0]
print "For loop range():        ", time_fibFR

time_fibFX = T.resource_runtime_range(F.fibFX, init, end, range_repeats)[0]
print "For loop xrange():       ", time_fibFX

time_fibFN = T.resource_runtime_range(F.fibFN, init, end, range_repeats)[0]
print "For loop numpy.arange(): ", time_fibFN

time_fibAnalytic = T.resource_runtime_range(F.fibAnalytic, init, end,
                                            range_repeats)[0]
print "Analytic:                ", time_fibAnalytic
Exemplo n.º 6
0
line6result = [2, 8, 4, 8, 2, 0, 0, 0, 0, 0, 0, 0]
results = [line1result, line2result, line3result, line4result, line5result, line6result]


# Test the merge functions

print ""
print "testing merge functions..."

for module in modules:
    for i in range(len(lines)):
        assert module.merge(lines[i]) == results[i]

print "all tests passed"
print "creating test lists..."
the_lists = T.create_lists(list_count, list_size)
print "test lists created"
print "performing time measurements..."

anontimes     = T.runtime_lists(Anon.merge, the_lists)
benjamintimes = T.runtime_lists(Benjamin.merge, the_lists)
liyuetimes    = T.runtime_lists(LiYue.merge, the_lists)
timtimes      = T.runtime_lists(Tim.merge, the_lists)

print ""
print "================="
print "Results:"
print ""
print "Anon total:       " + str(anontimes[0])
print "Anon average:     " + str(anontimes[1])
print ""