Example #1
0
    for mean1 in [(-1, 0), (1, 1)]:
        for mean2 in [(0, -1), (1, -1)]:
            jobs.append(generate_data(size, mean1, mean2))


def worker(model, args):
    X, Y = args
    model.compute_coefficients(X, Y)


# Profile the python implementation
model = LogisticRegressionPy()
timer = Timer()
for i, job in enumerate(jobs):
    worker(model, job)
py_time = timer.split()

# Profile the C++ implementation
model = LogisticRegressionCpp()
timer = Timer()
for job in jobs:
    worker(model, job)
cpp_time = timer.split()

# Build a nice graph
labels = ["Python", "C++"]
times = [py_time, cpp_time]
index = range(len(labels))
plt.bar(index, times)
plt.xlabel('Implementation language')
plt.ylabel('Runtime')
Example #2
0
def profiler(payload_size, num_calls):
    payload = [float(i) for i in range(payload_size)]
    timer = Timer()
    for _ in range(num_calls):
        noop(payload)
    return timer.split()
        for mean2 in [(0, -1), (1, -1)]:
            jobs.append(generate_data(size, mean1, mean2))

# Profile with differing numbers of python threads with a model that is
# single-threaded.
model = LogisticRegressionCpp()


def worker(args):
    X, Y = args
    model.compute_coefficients(X, Y)


times = []
for num_threads in range(1, 9):
    pool = ThreadPool(num_threads)
    timer = Timer()
    pool.map(worker, jobs)
    times.append((num_threads, timer.split()))

# Build a nice graph
labels = [n for n, _ in times]
times = [t for _, t in times]
index = range(len(labels))
plt.bar(index, times)
plt.xlabel('Number of threads')
plt.ylabel('Runtime')
plt.xticks(index, labels)
plt.title("C++ speed with varying numbers of python(!) threads")
plt.savefig("profile_pythreads.png")
from multiprocessing.pool import ThreadPool
from data import Timer
from module import noop

payload = [float(i) for i in range(1000000)]


def worker(arg):
    noop(payload)


jobs = range(200)

print("Threads", "Runtime", sep="\t")
for num_threads in range(1, 9):
    pool = ThreadPool(num_threads)
    timer = Timer()
    pool.map(worker, jobs)
    elapsed_time = timer.split()
    print(num_threads, elapsed_time, sep="\t")