From d4b79674ae0cfdf890d7e0ca8ed04c67ddde7905 Mon Sep 17 00:00:00 2001 From: "Casper V. Kristensen" Date: Sun, 21 Oct 2018 15:52:02 +0200 Subject: [PATCH] Altair? Requiescat in pace --- h2/tmptest.py | 105 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 97 insertions(+), 8 deletions(-) diff --git a/h2/tmptest.py b/h2/tmptest.py index c9d1d93..f3e8584 100644 --- a/h2/tmptest.py +++ b/h2/tmptest.py @@ -1,3 +1,4 @@ +import json import random from time import time from collections import namedtuple @@ -89,26 +90,27 @@ def sanity_check(): assert gift == graham == quick == mbch == mbch2 -def do_profile(): - print("==================================== PROFILE RESULTS ====================================") +def do_one_profile(num_points): + print(f"==================================== PROFILE ({num_points}) ====================================") random.seed(6) - points = {util.gen_point(0, 100) for _ in range(60_000)} + points = {util.gen_point(0, 100) for _ in range(num_points)} tests = [ - ("graham_scan", graham_scan), - ("gift_wrapper", rapper), - ("quick_hull", quick_hull), + #("graham_scan", graham_scan), + #("gift_wrapper", rapper), + #("quick_hull", quick_hull), ("mbc", mbc), ("mbc2", mbc2), ("mbc_no_shuffle", mbc_no_shuffle), ("mbc2_no_shuffle", mbc2_no_shuffle), ] + results = {} for algorithm, func in tests: Profiler.reset() func(points) - times = Profiler.results + times = dict(Profiler.results) print(f"-------------- {algorithm} --------------") print("Times:", times) @@ -119,7 +121,94 @@ def do_profile(): sum_profiled = sum(times.values()) - total print("Total Profiled:", sum_profiled) - print("Unaccounted:", total - sum_profiled) + unaccounted = total - sum_profiled + print("Unaccounted:", unaccounted) + + results[algorithm] = { + "times": times, + "total": total, + "total_profiled": sum_profiled, + "unaccounted": unaccounted, + } + + return results + + +def do_profile(): + import pandas as pd + import numpy as np + import altair as alt + + ### GATHER DATA ### + + #results = {num_points: do_one_profile(num_points) for num_points in (10_000, 30_000, 60_000)} + results = {"10000": {"mbc": {"times": {"finding median": 0.0010907649993896484, "partitioning set": 0.00837850570678711, "shuffling constraints": 0.01737236976623535, "solving 1D LP": 0.018637895584106445, "solving 2D LP": 0.023772716522216797, "finding bridge points": 0.00942373275756836, "pruning between line points": 0.0062139034271240234, "mbc": 0.08948898315429688}, "total": 0.08948898315429688, "total_profiled": 0.08488988876342773, "unaccounted": 0.004599094390869141}, "mbc2": {"times": {"extra pruning step": 0.021185636520385742, "finding median": 0.00042319297790527344, "partitioning set": 0.002390623092651367, "shuffling constraints": 0.00530552864074707, "solving 1D LP": 0.002721548080444336, "solving 2D LP": 0.004323244094848633, "finding bridge points": 0.0038061141967773438, "pruning between line points": 0.0017795562744140625, "mbc2": 0.0463566780090332}, "total": 0.0463566780090332, "total_profiled": 0.04193544387817383, "unaccounted": 0.004421234130859375}, "mbc_no_shuffle": {"times": {"finding median": 0.0011930465698242188, "partitioning set": 0.008675098419189453, "solving 1D LP": 0.012013912200927734, "solving 2D LP": 0.016475915908813477, "finding bridge points": 0.009999275207519531, "pruning between line points": 0.006704092025756836, "mbc_no_shuffle": 0.0634622573852539}, "total": 0.0634622573852539, "total_profiled": 0.05506134033203125, "unaccounted": 0.008400917053222656}, "mbc2_no_shuffle": {"times": {"extra pruning step": 0.020714282989501953, "finding median": 0.0004355907440185547, "partitioning set": 0.0022919178009033203, "solving 1D LP": 0.004298210144042969, "solving 2D LP": 0.005736112594604492, "finding bridge points": 0.004106044769287109, "pruning between line points": 0.0017347335815429688, "mbc2_no_shuffle": 0.04152178764343262}, "total": 0.04152178764343262, "total_profiled": 0.03931689262390137, "unaccounted": 0.00220489501953125}}, "30000": {"mbc": {"times": {"finding median": 0.0033922195434570312, "partitioning set": 0.027561187744140625, "shuffling constraints": 0.03943347930908203, "solving 1D LP": 0.03251838684082031, "solving 2D LP": 0.04914522171020508, "finding bridge points": 0.02995467185974121, "pruning between line points": 0.018335342407226562, "mbc": 0.23250341415405273}, "total": 0.23250341415405273, "total_profiled": 0.20034050941467285, "unaccounted": 0.03216290473937988}, "mbc2": {"times": {"extra pruning step": 0.07657957077026367, "finding median": 0.0013115406036376953, "partitioning set": 0.009799957275390625, "shuffling constraints": 0.01538705825805664, "solving 1D LP": 0.018373966217041016, "solving 2D LP": 0.023766040802001953, "finding bridge points": 0.01176595687866211, "pruning between line points": 0.0074269771575927734, "mbc2": 0.1977553367614746}, "total": 0.1977553367614746, "total_profiled": 0.16441106796264648, "unaccounted": 0.033344268798828125}, "mbc_no_shuffle": {"times": {"finding median": 0.003788471221923828, "partitioning set": 0.0294649600982666, "solving 1D LP": 0.01887059211730957, "solving 2D LP": 0.028406858444213867, "finding bridge points": 0.026410341262817383, "pruning between line points": 0.01907038688659668, "mbc_no_shuffle": 0.16133356094360352}, "total": 0.16133356094360352, "total_profiled": 0.12601161003112793, "unaccounted": 0.035321950912475586}, "mbc2_no_shuffle": {"times": {"extra pruning step": 0.07852339744567871, "finding median": 0.0014028549194335938, "partitioning set": 0.010036468505859375, "solving 1D LP": 0.008901834487915039, "solving 2D LP": 0.012744665145874023, "finding bridge points": 0.012570381164550781, "pruning between line points": 0.007673025131225586, "mbc2_no_shuffle": 0.14619135856628418}, "total": 0.14619135856628418, "total_profiled": 0.1318526268005371, "unaccounted": 0.01433873176574707}}, "60000": {"mbc": {"times": {"finding median": 0.006650209426879883, "partitioning set": 0.06662178039550781, "shuffling constraints": 0.08104324340820312, "solving 1D LP": 0.08928251266479492, "solving 2D LP": 0.12702107429504395, "finding bridge points": 0.060240983963012695, "pruning between line points": 0.042349815368652344, "mbc": 0.5576188564300537}, "total": 0.5576188564300537, "total_profiled": 0.4732096195220947, "unaccounted": 0.08440923690795898}, "mbc2": {"times": {"extra pruning step": 0.1567850112915039, "finding median": 0.001898050308227539, "partitioning set": 0.022631168365478516, "shuffling constraints": 0.031010150909423828, "solving 1D LP": 0.042766571044921875, "solving 2D LP": 0.0571141242980957, "finding bridge points": 0.025599241256713867, "pruning between line points": 0.014193058013916016, "mbc2": 0.36343836784362793}, "total": 0.36343836784362793, "total_profiled": 0.35199737548828125, "unaccounted": 0.01144099235534668}, "mbc_no_shuffle": {"times": {"finding median": 0.00703120231628418, "partitioning set": 0.06458783149719238, "solving 1D LP": 0.050481319427490234, "solving 2D LP": 0.07022786140441895, "finding bridge points": 0.06221938133239746, "pruning between line points": 0.04131031036376953, "mbc_no_shuffle": 0.3914146423339844}, "total": 0.3914146423339844, "total_profiled": 0.29585790634155273, "unaccounted": 0.09555673599243164}, "mbc2_no_shuffle": {"times": {"extra pruning step": 0.15882325172424316, "finding median": 0.0018322467803955078, "partitioning set": 0.024189233779907227, "solving 1D LP": 0.02034759521484375, "solving 2D LP": 0.02784895896911621, "finding bridge points": 0.022724390029907227, "pruning between line points": 0.015139102935791016, "mbc2_no_shuffle": 0.30243945121765137}, "total": 0.30243945121765137, "total_profiled": 0.2709047794342041, "unaccounted": 0.031534671783447266}}} + print("================== RESULTS ==================") + print(json.dumps(results)) + + ### PREPARE DATA ### + + num_points = list(results.keys()) + algorithms = [algorithm for algorithm in results[num_points[0]].keys()] + + steps = ( + "finding median", + "partitioning set", + "solving 1D LP", + "solving 2D LP", + "finding bridge points", + "pruning between line points", + "shuffling constraints", + "extra pruning step", + ) + + def prep_df(df, name): + df = df.stack().reset_index() + df.columns = ['c1', 'c2', 'values'] + df['DF'] = name + return df + + dfs = [] + for step in steps: + res = [[data["times"].get(step, 0) + for algorithm, data in results[points].items()] + for points in num_points] + df = pd.DataFrame(res, index=num_points, columns=algorithms) + dfs.append(prep_df(df, step)) + + df = pd.concat(dfs) + + ### PLOT DATA ### + + chart = alt.Chart(df).mark_bar().encode( + + # tell Altair which field to group columns on + x=alt.X('c2:N', + axis=alt.Axis( + title='')), + + # tell Altair which field to use as Y values and how to calculate + y=alt.Y('sum(values):Q', + axis=alt.Axis( + grid=False, + title='')), + + # tell Altair which field to use to use as the set of columns to be represented in each group + column=alt.Column('c1:N', + axis=alt.Axis( + title='')), + + # tell Altair which field to use for color segmentation + color=alt.Color('DF:N', + scale=alt.Scale( + # make it look pretty with an enjoyable color pallet + range=['#96ceb4', '#ffcc5c', '#ff6f69'], + ), + )) \ + .configure_facet_cell( + # remove grid lines around column clusters + strokeWidth=0.0) + chart.savechart('chart.html') if __name__ == '__main__':