<s> from __future__ import print_function <EOL> from collections import Iterable <EOL> import os <EOL> from time import time <EOL> from django . db import connections , router , transaction <EOL> from django . db . models import Max , F <EOL> import matplotlib . pyplot as plt <EOL> from matplotlib . ticker import FuncFormatter <EOL> import pandas as pd <EOL> from tqdm import tqdm <EOL> from . models import ( <EOL> TreePlace , MPTTPlace , TreebeardMPPlace , TreebeardNSPlace , TreebeardALPlace , <EOL> ) <EOL> from . utils import prefix_unit , SkipTest <EOL> DISK_USAGE = '<STR_LIT>' <EOL> READ_LATENCY = '<STR_LIT>' <EOL> WRITE_LATENCY = '<STR_LIT>' <EOL> BYTES_FORMATTER = FuncFormatter ( lambda v , pos : prefix_unit ( v , '<STR_LIT:B>' , - <NUM_LIT:3> ) ) <EOL> SECONDS_FORMATTER = FuncFormatter ( lambda v , pos : prefix_unit ( v , '<STR_LIT:s>' ) ) <EOL> class Benchmark : <EOL> models = { <EOL> MPTTPlace : '<STR_LIT>' , <EOL> TreePlace : '<STR_LIT>' , <EOL> TreebeardALPlace : '<STR_LIT>' , <EOL> TreebeardMPPlace : '<STR_LIT>' , <EOL> TreebeardNSPlace : '<STR_LIT>' , <EOL> } <EOL> siblings_per_level = ( <EOL> <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> , <EOL> ) <EOL> tests = { } <EOL> ticks_formatters = { <EOL> DISK_USAGE : BYTES_FORMATTER , <EOL> READ_LATENCY : SECONDS_FORMATTER , <EOL> WRITE_LATENCY : SECONDS_FORMATTER , <EOL> } <EOL> results_path = '<STR_LIT>' <EOL> def __init__ ( self ) : <EOL> self . data = [ ] <EOL> self . router = router . routers [ <NUM_LIT:0> ] <EOL> self . rows_count = <NUM_LIT:0> <EOL> n = <NUM_LIT:1> <EOL> for i in self . siblings_per_level : <EOL> n *= i <EOL> self . rows_count += n <EOL> if not os . path . exists ( self . results_path ) : <EOL> os . makedirs ( self . results_path ) <EOL> @ property <EOL> def current_db_alias ( self ) : <EOL> return self . router . db_alias <EOL> @ current_db_alias . setter <EOL> def current_db_alias ( self , db_alias ) : <EOL> self . router . db_alias = db_alias <EOL> def add_data ( self , model , test_name , count , value , y_label = READ_LATENCY ) : <EOL> self . data . append ( { <EOL> '<STR_LIT>' : connections [ self . current_db_alias ] . vendor , <EOL> '<STR_LIT>' : test_name , <EOL> '<STR_LIT>' : count , <EOL> '<STR_LIT>' : self . models [ model ] , <EOL> '<STR_LIT>' : value , <EOL> '<STR_LIT>' : y_label , <EOL> } ) <EOL> def populate_database ( self , model , level = <NUM_LIT:1> , parents = ( None , ) ) : <EOL> n_siblings = self . siblings_per_level [ level - <NUM_LIT:1> ] <EOL> for parent in parents : <EOL> if model in ( TreePlace , TreebeardALPlace ) : <EOL> bulk = [ model ( parent = parent ) <EOL> for _ in range ( n_siblings ) ] <EOL> model . objects . bulk_create ( bulk ) <EOL> objects = model . objects . filter ( parent = parent ) <EOL> elif model in ( TreebeardMPPlace , TreebeardNSPlace ) : <EOL> if parent is not None : <EOL> parent = model . objects . get ( pk = parent . pk ) <EOL> objects = [ model . add_root ( ) if parent is None <EOL> else parent . add_child ( ) for _ in range ( n_siblings ) ] <EOL> else : <EOL> objects = [ model . objects . create ( parent = parent ) <EOL> for _ in range ( n_siblings ) ] <EOL> yield model . objects . count ( ) <EOL> if level < len ( self . siblings_per_level ) : <EOL> for count in self . populate_database ( model , level + <NUM_LIT:1> , objects ) : <EOL> yield count <EOL> def create_databases ( self ) : <EOL> old_db_names = { } <EOL> for alias in connections : <EOL> conn = connections [ alias ] <EOL> old_db_names [ alias ] = conn . settings_dict [ '<STR_LIT>' ] <EOL> conn . creation . create_test_db ( autoclobber = True ) <EOL> @ classmethod <EOL> def register_test ( cls , name , models = None , y_label = READ_LATENCY ) : <EOL> if models is None : <EOL> models = cls . models <EOL> if not isinstance ( models , Iterable ) : <EOL> models = ( models , ) <EOL> def inner ( test_class ) : <EOL> for model in models : <EOL> cls . tests [ ( name , model , y_label ) ] = test_class <EOL> return test_class <EOL> return inner <EOL> def run_tests ( self , tested_model , count ) : <EOL> connection = connections [ self . current_db_alias ] <EOL> for ( test_name , model , y_label ) , test_class in self . tests . items ( ) : <EOL> if model is not tested_model : <EOL> continue <EOL> benchmark_test = test_class ( self , model ) <EOL> with transaction . atomic ( using = self . current_db_alias ) : <EOL> try : <EOL> benchmark_test . setup ( ) <EOL> except SkipTest : <EOL> value = elapsed_time = None <EOL> else : <EOL> start = time ( ) <EOL> value = benchmark_test . run ( ) <EOL> elapsed_time = time ( ) - start <EOL> connection . needs_rollback = True <EOL> if value is None : <EOL> value = elapsed_time <EOL> self . add_data ( model , test_name , count , value , y_label = y_label ) <EOL> def plot ( self , df , database_name , test_name , y_label ) : <EOL> means = df . rolling ( <NUM_LIT> ) . mean ( ) <EOL> ax = means . plot ( <EOL> title = test_name , alpha = <NUM_LIT> , <EOL> xlim = ( <NUM_LIT:0> , means . index . max ( ) * <NUM_LIT> ) , <EOL> ylim = ( <NUM_LIT:0> , means . max ( ) . max ( ) * <NUM_LIT> ) , <EOL> ) <EOL> ax . set ( xlabel = '<STR_LIT>' , ylabel = y_label ) <EOL> ax . xaxis . set_major_formatter ( <EOL> FuncFormatter ( lambda v , pos : prefix_unit ( v , '<STR_LIT>' , - <NUM_LIT:3> ) ) ) <EOL> if y_label in self . ticks_formatters : <EOL> ax . yaxis . set_major_formatter ( self . ticks_formatters [ y_label ] ) <EOL> legend = ax . legend ( <EOL> loc = '<STR_LIT>' , bbox_to_anchor = ( <NUM_LIT:0.5> , <NUM_LIT:0.0> ) , <EOL> bbox_transform = plt . gcf ( ) . transFigure , <EOL> fancybox = True , shadow = True , ncol = <NUM_LIT:3> ) <EOL> plt . savefig ( <EOL> os . path . join ( self . results_path , <EOL> '<STR_LIT>' % ( database_name , test_name ) ) , <EOL> bbox_extra_artists = ( legend , ) , bbox_inches = '<STR_LIT>' , <EOL> ) <EOL> def run ( self ) : <EOL> self . create_databases ( ) <EOL> for db_alias in connections : <EOL> self . current_db_alias = db_alias <EOL> connection = connections [ db_alias ] <EOL> for model in sorted ( self . models , key = lambda m : m . __name__ ) : <EOL> print ( '<STR_LIT:->' * <NUM_LIT:50> ) <EOL> print ( '<STR_LIT>' % ( self . models [ model ] , connection . vendor ) ) <EOL> it = self . populate_database ( model ) <EOL> progress = tqdm ( it , total = self . rows_count ) <EOL> elapsed_time = <NUM_LIT:0.0> <EOL> while True : <EOL> try : <EOL> start = time ( ) - elapsed_time <EOL> count = next ( it ) <EOL> elapsed_time = time ( ) - start <EOL> except StopIteration : <EOL> break <EOL> progress . update ( count - progress . n ) <EOL> self . add_data ( model , '<STR_LIT>' , count , <EOL> elapsed_time , y_label = WRITE_LATENCY ) <EOL> with connection . cursor ( ) as cursor : <EOL> cursor . execute ( <EOL> '<STR_LIT>' % model . _meta . db_table ) <EOL> cursor . execute ( <EOL> '<STR_LIT>' % model . _meta . db_table ) <EOL> self . run_tests ( model , count ) <EOL> model . objects . all ( ) . delete ( ) <EOL> df = pd . DataFrame ( self . data ) <EOL> df . to_csv ( os . path . join ( self . results_path , '<STR_LIT>' ) , index = False ) <EOL> stats_df = df . set_index ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> stats_df . sort_index ( inplace = True ) <EOL> group_by = stats_df . groupby ( level = [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> min_values_series = group_by . min ( ) [ '<STR_LIT>' ] <EOL> max_values_series = group_by . max ( ) [ '<STR_LIT>' ] <EOL> stats_df [ '<STR_LIT>' ] = ( ( stats_df [ '<STR_LIT>' ] - min_values_series ) <EOL> / ( max_values_series - min_values_series ) ) <EOL> stats_df [ '<STR_LIT>' ] = stats_df [ '<STR_LIT>' ] . fillna ( <NUM_LIT:1.0> ) <EOL> stats_df = stats_df . groupby ( [ '<STR_LIT>' , '<STR_LIT>' ] ) . mean ( ) <EOL> stats_df [ '<STR_LIT>' ] = ( ( <NUM_LIT:20> * ( <NUM_LIT:1> - stats_df [ '<STR_LIT>' ] ) ) <EOL> . apply ( lambda f : '<STR_LIT>' % f ) ) <EOL> stats_df . to_html ( os . path . join ( self . results_path , '<STR_LIT>' ) , <EOL> header = False ) <EOL> df . set_index ( '<STR_LIT>' , inplace = True ) <EOL> for database_name in df [ '<STR_LIT>' ] . unique ( ) : <EOL> for test_name in df [ '<STR_LIT>' ] . unique ( ) : <EOL> sub_df = df [ ( df [ '<STR_LIT>' ] == database_name ) <EOL> & ( df [ '<STR_LIT>' ] == test_name ) ] <EOL> y_labels = sub_df [ '<STR_LIT>' ] . unique ( ) <EOL> assert len ( y_labels ) == <NUM_LIT:1> <EOL> sub_df = sub_df . pivot ( columns = '<STR_LIT>' , values = '<STR_LIT>' ) <EOL> self . plot ( sub_df , database_name , test_name , y_labels [ <NUM_LIT:0> ] ) <EOL> class BenchmarkTest : <EOL> def __init__ ( self , benchmark , model ) : <EOL> self . benchmark = benchmark <EOL> self . model = model <EOL> def setup ( self ) : <EOL> pass <EOL> def run ( self ) : <EOL> raise NotImplementedError <EOL> @ Benchmark . register_test ( '<STR_LIT>' , <EOL> y_label = DISK_USAGE ) <EOL> class TestDiskUsage ( BenchmarkTest ) : <EOL> def run ( self ) : <EOL> with connections [ self . benchmark . current_db_alias ] . cursor ( ) as cursor : <EOL> cursor . execute ( "<STR_LIT>" <EOL> % self . model . _meta . db_table ) <EOL> return cursor . fetchone ( ) [ <NUM_LIT:0> ] <EOL> class GetRootMixin : <EOL> def setup ( self ) : <EOL> qs = self . model . _default_manager . all ( ) <EOL> qs = ( qs . filter ( depth = <NUM_LIT:1> ) <EOL> if self . model in ( TreebeardMPPlace , TreebeardNSPlace ) <EOL> else qs . filter ( parent__isnull = True ) ) <EOL> self . root = qs [ qs . count ( ) // <NUM_LIT:2> ] <EOL> super ( GetRootMixin , self ) . setup ( ) <EOL> class GetBranchMixin : <EOL> def setup ( self ) : <EOL> super ( GetBranchMixin , self ) . setup ( ) <EOL> qs = self . model . _default_manager . all ( ) <EOL> if hasattr ( self , '<STR_LIT:root>' ) : <EOL> descendants = self . root . get_descendants ( ) <EOL> if isinstance ( descendants , list ) : <EOL> descendants = [ d . pk for d in descendants ] <EOL> qs = qs . exclude ( pk__in = descendants ) <EOL> if self . model is MPTTPlace : <EOL> qs = qs . filter ( level = <NUM_LIT:1> ) <EOL> elif self . model is TreePlace : <EOL> qs = qs . filter ( path__level = <NUM_LIT:2> ) <EOL> elif self . model is TreebeardALPlace : <EOL> qs = qs . filter ( parent__isnull = False , parent__parent__isnull = True ) <EOL> else : <EOL> qs = qs . filter ( depth = <NUM_LIT:2> ) <EOL> try : <EOL> self . branch = qs [ qs . count ( ) // <NUM_LIT:2> ] <EOL> except IndexError : <EOL> raise SkipTest <EOL> class GetLeafMixin : <EOL> def setup ( self ) : <EOL> super ( GetLeafMixin , self ) . setup ( ) <EOL> qs = self . model . _default_manager . all ( ) <EOL> if hasattr ( self , '<STR_LIT:root>' ) : <EOL> descendants = self . root . get_descendants ( ) <EOL> if isinstance ( descendants , list ) : <EOL> descendants = [ d . pk for d in descendants ] <EOL> qs = qs . exclude ( pk = self . root . pk ) . exclude ( pk__in = descendants ) <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> descendants = self . branch . get_descendants ( ) <EOL> if isinstance ( descendants , list ) : <EOL> descendants = [ d . pk for d in descendants ] <EOL> qs = qs . exclude ( pk = self . branch . pk ) . exclude ( pk__in = descendants ) <EOL> qs = ( qs . annotate ( n = Max ( '<STR_LIT>' ) ) . filter ( depth = F ( '<STR_LIT:n>' ) , depth__gt = <NUM_LIT:1> ) <EOL> if self . model in ( TreebeardMPPlace , TreebeardNSPlace ) <EOL> else qs . filter ( children__isnull = True , parent__isnull = False ) ) <EOL> try : <EOL> self . leaf = qs [ qs . count ( ) // <NUM_LIT:2> ] <EOL> except IndexError : <EOL> raise SkipTest <EOL> @ Benchmark . register_test ( '<STR_LIT>' ) <EOL> class TestGetChildrenRoot ( GetRootMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> list ( self . root . get_children ( ) ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' ) <EOL> class TestGetChildrenBranch ( GetBranchMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> list ( self . branch . get_children ( ) ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' ) <EOL> class TestGetChildrenLeaf ( GetLeafMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> list ( self . leaf . get_children ( ) ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' , <EOL> ( MPTTPlace , TreePlace ) ) <EOL> class TestGetChildrenCountRoot ( GetRootMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . root . get_children ( ) . count ( ) <EOL> @ Benchmark . register_test ( <EOL> '<STR_LIT>' , <EOL> ( TreebeardALPlace , TreebeardMPPlace , TreebeardNSPlace ) ) <EOL> class TestGetChildrenCountRoot ( GetRootMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . root . get_children_count ( ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' , <EOL> ( MPTTPlace , TreePlace ) ) <EOL> class TestGetChildrenCountBranch ( GetBranchMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . branch . get_children ( ) . count ( ) <EOL> @ Benchmark . register_test ( <EOL> '<STR_LIT>' , <EOL> ( TreebeardALPlace , TreebeardMPPlace , TreebeardNSPlace ) ) <EOL> class TestGetChildrenCountBranch ( GetBranchMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . branch . get_children_count ( ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' , <EOL> ( MPTTPlace , TreePlace ) ) <EOL> class TestGetChildrenCountLeaf ( GetLeafMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . leaf . get_children ( ) . count ( ) <EOL> @ Benchmark . register_test ( <EOL> '<STR_LIT>' , <EOL> ( TreebeardALPlace , TreebeardMPPlace , TreebeardNSPlace ) ) <EOL> class TestGetChildrenCounteaf ( GetLeafMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . leaf . get_children_count ( ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' ) <EOL> class TestGetFilteredChildrenCountRoot ( GetRootMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . root . get_children ( ) . filter ( pk__contains = '<STR_LIT:1>' ) . count ( ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' ) <EOL> class TestGetFilteredChildrenCountBranch ( GetBranchMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . branch . get_children ( ) . filter ( pk__contains = '<STR_LIT:1>' ) . count ( ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' ) <EOL> class TestGetFilteredChildrenCountLeaf ( GetLeafMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . leaf . get_children ( ) . filter ( pk__contains = '<STR_LIT:1>' ) . count ( ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' ) <EOL> class TestGetAncestorsRoot ( GetRootMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> list ( self . root . get_ancestors ( ) ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' , ) <EOL> class TestGetAncestorsBranch ( GetBranchMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> list ( self . branch . get_ancestors ( ) ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' ) <EOL> class TestGetAncestorsLeaf ( GetLeafMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> list ( self . leaf . get_ancestors ( ) ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' ) <EOL> class TestGetDescendantsRoot ( GetRootMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> list ( self . root . get_descendants ( ) ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' ) <EOL> class TestGetDescendantsBranch ( GetBranchMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> list ( self . branch . get_descendants ( ) ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' ) <EOL> class TestGetDescendantsLeaf ( GetLeafMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> list ( self . leaf . get_descendants ( ) ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' , TreePlace ) <EOL> class TestGetDescendantsCountRoot ( GetRootMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . root . get_descendants ( ) . count ( ) <EOL> @ Benchmark . register_test ( <EOL> '<STR_LIT>' , <EOL> ( MPTTPlace , TreebeardALPlace , TreebeardMPPlace , TreebeardNSPlace ) ) <EOL> class TestGetDescendantsCountRoot ( GetRootMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . root . get_descendant_count ( ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' , TreePlace ) <EOL> class TestGetDescendantsCountBranch ( GetBranchMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . branch . get_descendants ( ) . count ( ) <EOL> @ Benchmark . register_test ( <EOL> '<STR_LIT>' , <EOL> ( MPTTPlace , TreebeardALPlace , TreebeardMPPlace , TreebeardNSPlace ) ) <EOL> class TestGetDescendantsCountBranch ( GetBranchMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . branch . get_descendant_count ( ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' , TreePlace ) <EOL> class TestGetDescendantsCountLeaf ( GetLeafMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . leaf . get_descendants ( ) . count ( ) <EOL> @ Benchmark . register_test ( <EOL> '<STR_LIT>' , <EOL> ( MPTTPlace , TreebeardALPlace , TreebeardMPPlace , TreebeardNSPlace ) ) <EOL> class TestGetDescendantsCountLeaf ( GetLeafMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . leaf . get_descendant_count ( ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' ) <EOL> class TestGetFilteredDescendantsCountRoot ( GetRootMixin , BenchmarkTest ) : <EOL> def setup ( self ) : <EOL> if self . model is TreebeardALPlace : <EOL> raise SkipTest <EOL> super ( TestGetFilteredDescendantsCountRoot , self ) . setup ( ) <EOL> def run ( self ) : <EOL> self . root . get_descendants ( ) . filter ( pk__contains = '<STR_LIT:1>' ) . count ( ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' ) <EOL> class TestGetFilteredDescendantsCountBranch ( GetBranchMixin , BenchmarkTest ) : <EOL> def setup ( self ) : <EOL> if self . model is TreebeardALPlace : <EOL> raise SkipTest <EOL> super ( TestGetFilteredDescendantsCountBranch , self ) . setup ( ) <EOL> def run ( self ) : <EOL> self . branch . get_descendants ( ) . filter ( pk__contains = '<STR_LIT:1>' ) . count ( ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' ) <EOL> class TestGetFilteredDescendantsCountLeaf ( GetLeafMixin , BenchmarkTest ) : <EOL> def setup ( self ) : <EOL> if self . model is TreebeardALPlace : <EOL> raise SkipTest <EOL> super ( TestGetFilteredDescendantsCountLeaf , self ) . setup ( ) <EOL> def run ( self ) : <EOL> self . leaf . get_descendants ( ) . filter ( pk__contains = '<STR_LIT:1>' ) . count ( ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' , ( MPTTPlace , TreePlace ) ) <EOL> class TestGetSiblingsRoot ( GetRootMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> list ( self . root . get_siblings ( include_self = True ) ) <EOL> @ Benchmark . register_test ( <EOL> '<STR_LIT>' , <EOL> ( TreebeardALPlace , TreebeardMPPlace , TreebeardNSPlace ) ) <EOL> class TestGetSiblingsRoot ( GetRootMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> list ( self . root . get_siblings ( ) ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' , ( MPTTPlace , TreePlace ) ) <EOL> class TestGetSiblingsBranch ( GetBranchMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> list ( self . branch . get_siblings ( include_self = True ) ) <EOL> @ Benchmark . register_test ( <EOL> '<STR_LIT>' , <EOL> ( TreebeardALPlace , TreebeardMPPlace , TreebeardNSPlace ) ) <EOL> class TestGetSiblingsBranch ( GetBranchMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> list ( self . branch . get_siblings ( ) ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' , ( MPTTPlace , TreePlace ) ) <EOL> class TestGetSiblingsLeaf ( GetLeafMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> list ( self . leaf . get_siblings ( include_self = True ) ) <EOL> @ Benchmark . register_test ( <EOL> '<STR_LIT>' , <EOL> ( TreebeardALPlace , TreebeardMPPlace , TreebeardNSPlace ) ) <EOL> class TestGetSiblingsLeaf ( GetLeafMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> list ( self . leaf . get_siblings ( ) ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' , MPTTPlace ) <EOL> class TestGetPrevSiblingRoot ( GetRootMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . root . get_previous_sibling ( ) <EOL> @ Benchmark . register_test ( <EOL> '<STR_LIT>' , <EOL> ( TreePlace , TreebeardALPlace , TreebeardMPPlace , TreebeardNSPlace ) ) <EOL> class TestGetPrevSiblingRoot ( GetRootMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . root . get_prev_sibling ( ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' , MPTTPlace ) <EOL> class TestGetPrevSiblingBranch ( GetBranchMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . branch . get_previous_sibling ( ) <EOL> @ Benchmark . register_test ( <EOL> '<STR_LIT>' , <EOL> ( TreePlace , TreebeardALPlace , TreebeardMPPlace , TreebeardNSPlace ) ) <EOL> class TestGetPrevSiblingBranch ( GetBranchMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . branch . get_prev_sibling ( ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' , MPTTPlace ) <EOL> class TestGetPrevSiblingLeaf ( GetLeafMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . leaf . get_previous_sibling ( ) <EOL> @ Benchmark . register_test ( <EOL> '<STR_LIT>' , <EOL> ( TreePlace , TreebeardALPlace , TreebeardMPPlace , TreebeardNSPlace ) ) <EOL> class TestGetPrevSiblingLeaf ( GetLeafMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . leaf . get_prev_sibling ( ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' ) <EOL> class TestGetNextSiblingRoot ( GetRootMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . root . get_next_sibling ( ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' ) <EOL> class TestGetNextSiblingBranch ( GetBranchMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . branch . get_next_sibling ( ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' ) <EOL> class TestGetNextSiblingLeaf ( GetLeafMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . leaf . get_next_sibling ( ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' , MPTTPlace ) <EOL> class TestGetRoots ( BenchmarkTest ) : <EOL> def run ( self ) : <EOL> list ( self . model . _default_manager . root_nodes ( ) ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' , TreePlace ) <EOL> class TestGetRoots ( BenchmarkTest ) : <EOL> def run ( self ) : <EOL> list ( self . model . get_roots ( ) ) <EOL> @ Benchmark . register_test ( <EOL> '<STR_LIT>' , ( TreebeardALPlace , TreebeardMPPlace , TreebeardNSPlace ) ) <EOL> class TestGetRoots ( BenchmarkTest ) : <EOL> def run ( self ) : <EOL> list ( self . model . get_root_nodes ( ) ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' , MPTTPlace , y_label = WRITE_LATENCY ) <EOL> class TestRebuildPaths ( BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . model . _default_manager . rebuild ( ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' , TreePlace , y_label = WRITE_LATENCY ) <EOL> class TestRebuildPaths ( BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . model . rebuild_paths ( ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' , ( TreebeardALPlace , TreebeardNSPlace ) , <EOL> y_label = WRITE_LATENCY ) <EOL> class TestRebuildPaths ( BenchmarkTest ) : <EOL> def setup ( self ) : <EOL> raise SkipTest <EOL> @ Benchmark . register_test ( '<STR_LIT>' , TreebeardMPPlace , <EOL> y_label = WRITE_LATENCY ) <EOL> class TestRebuildPaths ( BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . model . fix_tree ( ) <EOL> @ Benchmark . register_test ( <EOL> '<STR_LIT>' , <EOL> ( MPTTPlace , TreePlace , TreebeardALPlace ) , y_label = WRITE_LATENCY ) <EOL> class TestCreateRoot ( BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . model . objects . create ( ) <EOL> @ Benchmark . register_test ( <EOL> '<STR_LIT>' , <EOL> ( TreebeardMPPlace , TreebeardNSPlace ) , y_label = WRITE_LATENCY ) <EOL> class TestCreateRoot ( BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . model . add_root ( ) <EOL> @ Benchmark . register_test ( <EOL> '<STR_LIT>' , <EOL> ( MPTTPlace , TreePlace , TreebeardALPlace ) , y_label = WRITE_LATENCY ) <EOL> class TestCreateBranch ( GetRootMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . model . objects . create ( parent = self . root ) <EOL> @ Benchmark . register_test ( <EOL> '<STR_LIT>' , <EOL> ( TreebeardMPPlace , TreebeardNSPlace ) , y_label = WRITE_LATENCY ) <EOL> class TestCreateBranch ( GetRootMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . root . add_child ( ) <EOL> @ Benchmark . register_test ( <EOL> '<STR_LIT>' , <EOL> ( MPTTPlace , TreePlace , TreebeardALPlace ) , y_label = WRITE_LATENCY ) <EOL> class TestCreateLeaf ( GetLeafMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . model . objects . create ( parent = self . leaf ) <EOL> @ Benchmark . register_test ( <EOL> '<STR_LIT>' , <EOL> ( TreebeardMPPlace , TreebeardNSPlace ) , y_label = WRITE_LATENCY ) <EOL> class TestCreateLeaf ( GetLeafMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . leaf . add_child ( ) <EOL> @ Benchmark . register_test ( <EOL> '<STR_LIT>' , <EOL> ( MPTTPlace , TreePlace , TreebeardALPlace ) , y_label = WRITE_LATENCY ) <EOL> class TestMoveRootToBranch ( GetBranchMixin , GetRootMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . root . parent = self . branch <EOL> self . root . save ( ) <EOL> @ Benchmark . register_test ( <EOL> '<STR_LIT>' , <EOL> ( TreebeardMPPlace , TreebeardNSPlace ) , y_label = WRITE_LATENCY ) <EOL> class TestMoveRootToBranch ( GetBranchMixin , GetRootMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . root . move ( self . branch , pos = '<STR_LIT>' ) <EOL> @ Benchmark . register_test ( <EOL> '<STR_LIT>' , <EOL> ( MPTTPlace , TreePlace , TreebeardALPlace ) , y_label = WRITE_LATENCY ) <EOL> class TestMoveRootToLeaf ( GetLeafMixin , GetRootMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . root . parent = self . leaf <EOL> self . root . save ( ) <EOL> @ Benchmark . register_test ( <EOL> '<STR_LIT>' , <EOL> ( TreebeardMPPlace , TreebeardNSPlace ) , y_label = WRITE_LATENCY ) <EOL> class TestMoveRootToLeaf ( GetLeafMixin , GetRootMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . root . move ( self . leaf , pos = '<STR_LIT>' ) <EOL> @ Benchmark . register_test ( <EOL> '<STR_LIT>' , <EOL> ( MPTTPlace , TreePlace , TreebeardALPlace ) , y_label = WRITE_LATENCY ) <EOL> class TestMoveBranchToRoot ( GetBranchMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . branch . parent = None <EOL> self . branch . save ( ) <EOL> @ Benchmark . register_test ( <EOL> '<STR_LIT>' , <EOL> ( TreebeardMPPlace , TreebeardNSPlace ) , y_label = WRITE_LATENCY ) <EOL> class TestMoveBranchToRoot ( GetBranchMixin , GetRootMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . branch . move ( self . root , pos = '<STR_LIT>' ) <EOL> @ Benchmark . register_test ( <EOL> '<STR_LIT>' , <EOL> ( MPTTPlace , TreePlace , TreebeardALPlace ) , y_label = WRITE_LATENCY ) <EOL> class TestMoveBranchToLeaf ( GetLeafMixin , GetBranchMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . branch . parent = self . leaf <EOL> self . branch . save ( ) <EOL> @ Benchmark . register_test ( <EOL> '<STR_LIT>' , <EOL> ( TreebeardMPPlace , TreebeardNSPlace ) , y_label = WRITE_LATENCY ) <EOL> class TestMoveBranchToLeaf ( GetLeafMixin , GetBranchMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . branch . move ( self . leaf , pos = '<STR_LIT>' ) <EOL> @ Benchmark . register_test ( <EOL> '<STR_LIT>' , <EOL> ( MPTTPlace , TreePlace , TreebeardALPlace ) , y_label = WRITE_LATENCY ) <EOL> class TestMoveLeafToRoot ( GetLeafMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . leaf . parent = None <EOL> self . leaf . save ( ) <EOL> @ Benchmark . register_test ( <EOL> '<STR_LIT>' , <EOL> ( TreebeardMPPlace , TreebeardNSPlace ) , y_label = WRITE_LATENCY ) <EOL> class TestMoveLeafToRoot ( GetLeafMixin , GetRootMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . leaf . move ( self . root , pos = '<STR_LIT>' ) <EOL> @ Benchmark . register_test ( <EOL> '<STR_LIT>' , <EOL> ( MPTTPlace , TreePlace , TreebeardALPlace ) , y_label = WRITE_LATENCY ) <EOL> class TestMoveLeafToBranch ( GetLeafMixin , GetRootMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . leaf . parent = self . root <EOL> self . leaf . save ( ) <EOL> @ Benchmark . register_test ( <EOL> '<STR_LIT>' , <EOL> ( TreebeardMPPlace , TreebeardNSPlace ) , y_label = WRITE_LATENCY ) <EOL> class TestMoveLeafToBranch ( GetLeafMixin , GetRootMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . leaf . move ( self . root , pos = '<STR_LIT>' ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' , y_label = WRITE_LATENCY ) <EOL> class TestDeleteRoot ( GetRootMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . root . delete ( ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' , y_label = WRITE_LATENCY ) <EOL> class TestDeleteBranch ( GetBranchMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . branch . delete ( ) <EOL> @ Benchmark . register_test ( '<STR_LIT>' , y_label = WRITE_LATENCY ) <EOL> class TestDeleteLeaf ( GetLeafMixin , BenchmarkTest ) : <EOL> def run ( self ) : <EOL> self . leaf . delete ( ) </s>
