3.1. SpeedIT package

3.1.1. Submodules

3.1.2. SpeedIT.BenchmarkIT module

Benchmark module: can also compare multiple functions

SpeedIT.BenchmarkIT.speedit_benchmark(func_dict, setup_line_list, use_func_name=True, output_in_sec=False, benchmarkit__with_gc=False, benchmarkit__check_too_fast=True, benchmarkit__rank_by='best', benchmarkit__run_sec=1, benchmarkit__repeat=3)

Returns one txt string for the ready comparison table: format is conform with reStructuredText

Usage:

func_dict = {
   'function_f1': (function_f1, [act_one_hamlet], {}),
   'function_f2': (function_f2, [act_one_hamlet], {}),
   'function_f3': (function_f3, [act_one_hamlet], {}),
}

setup_line_list = [
   'from random import shuffle',
   'from os.path import abspath, dirname, join',
   'MY_CONSTANT = 15'
]

benchmark_result = BenchmarkIT.speedit_benchmark(func_dict, setup_line_list, benchmarkit__run_sec=1.0, output_in_sec=True, use_func_name=True, benchmarkit__with_gc=False, benchmarkit__repeat=3)
Parameters:
  • func_dict (dict) – mapping function names to functions value format: tuple (function, list_of_positional_arguments, dictionary_of_keyword_arguments)
  • setup_line_list (list) –

    of strings with import lines needed by the functions any global data ect..

    Warning

    no multiline string or indented code line

  • use_func_name (bool) – if True the function name will be used in the output name if False the func_dict key will be used in the the output name
  • output_in_sec (int) – if true the output is keep in seconds if false it is transformed to: second (s) millisecond (ms) One thousandth of one second microsecond (µs) One millionth of one second nanosecond (ns) One billionth of one second
  • benchmarkit__with_gc (bool) – if True gc is kept on during timing: if False: turns off garbage collection during the timing
  • benchmarkit__check_too_fast (bool) –

    if True and aa code block is timed faster than a Reference-Time an Exception is raised.

    • Reference-Time: the smallest difference of calling perf_counter() immediately after each other a couple of times

    See also

    _helper_get_perf_counter_reference_time()

  • benchmarkit__rank_by (str) – best or average
  • benchmarkit__run_sec (float or -1 or None) –

    the number of loops per run is scaled to approximately fit the benchmarkit__run_sec

    • if benchmarkit__run_sec is -1: then the generated function source code is only run once
    • if benchmarkit__run_sec is None: then the generated function source code is only printed
      this is mainly useful to see the exact final func code block which will be timed.
  • benchmarkit__repeat (int) – how often everything is repeated This is a convenience variable that calls the whole setup repeatedly
Returns:

ready to print or write to file: table format is conform with reStructuredText

Return type:

str

Raises:

SpeedIT.Err

3.1.3. SpeedIT.DisassembleIT module

Disassemble module

SpeedIT.DisassembleIT.speedit_disassemble(func_dict, use_func_name=True)

Returns one txt string for: table format is conform with reStructuredText

Note

func_positional_arguments, func_keyword_arguments of the func_dict are not actually used but are required so it works similar to all SpeedIT modules

Parameters:
  • func_dict (dict) – mapping function names to functions value format: tuple (function, list_of_positional_arguments, dictionary_of_keyword_arguments)
  • use_func_name (bool) – if True the function name will be used in the output name if False the func_dict key will be used in the the output name
Returns:

ready to print or write to file: table format is conform with reStructuredText

  • starts_line: line started by this opcode (if any), otherwise None
  • offset: start index of operation within bytecode sequence
  • opname: human readable name for operation
  • arg: numeric argument to operation (if any), otherwise None
  • argval: resolved arg value (if known), otherwise same as arg
  • argrepr: human readable description of operation argument
  • is_jump_target: True if other code jumps to here, otherwise False
  • line: code line

Return type:

str

3.1.4. SpeedIT.LineMemoryProfileIT module

Line memory module: much of the code is based on: a reduced version of parts of: https://github.com/fabianp/memory_profiler memory_profiler: License: Simplified BSD

SpeedIT.LineMemoryProfileIT.speedit_line_memory(func_dict, use_func_name=True)

Returns one txt string for: table format is conform with reStructuredText

Parameters:
  • func_dict (dict) –

    mapping function names to functions value format: tuple (function, list_of_positional_arguments, dictionary_of_keyword_arguments)

    Note

    if there is a key: loops in the dictionary_of_keyword_arguments it will be overwritten with the value 1 to make it work with the main SpeedIT

  • use_func_name (bool) – if True the function name will be used in the output name column if False the func_dict key will be used in the the output name column
Returns:

ready to print or write to file: table format is conform with reStructuredText

  • line num: code line number
  • memory_usage: memory_usage
  • incr. memory_usage: increment_memory_usage
  • line: code line

Return type:

str

3.1.5. SpeedIT.MainCode module

Main SpeedIT module

SpeedIT.MainCode.speed_it(func_dict, setup_line_list, enable_benchmarkit=True, enable_profileit=True, enable_linememoryprofileit=True, enable_disassembleit=True, use_func_name=True, output_in_sec=False, profileit__max_slashes_fileinfo=2, profileit__repeat=1, benchmarkit__with_gc=False, benchmarkit__check_too_fast=True, benchmarkit__rank_by='best', benchmarkit__run_sec=1, benchmarkit__repeat=3)

Returns one txt string for all: Benchmark-IT, Profile-IT, Line-Memory-Profile-IT, Disassemble-IT: format is conform with reStructuredText

Usage:

func_dict = {
   'function_f1': (function_f1, [act_one_hamlet], {}),
   'function_f2': (function_f2, [act_one_hamlet], {}),
   'function_f3': (function_f3, [act_one_hamlet], {}),
}

setup_line_list = [
   'from random import shuffle',
   'from os.path import abspath, dirname, join',
   'MY_CONSTANT = 15'
]
Parameters:
  • func_dict (dict) – mapping function names to functions value format: tuple (function, list_of_positional_arguments, dictionary_of_keyword_arguments)
  • setup_line_list (list) –

    of strings with import lines needed by the functions any global data ect..

    Warning

    no multiline string or indented code line

  • use_func_name (bool) – if True the function name will be used in the output name if False the func_dict key will be used in the the output name
  • output_in_sec (int) – if true the output is keep in seconds if false it is transformed to: second (s) millisecond (ms) One thousandth of one second microsecond (µs) One millionth of one second nanosecond (ns) One billionth of one second
  • profileit__max_slashes_fileinfo (int) – to adjust max path levels in the profile info
  • profileit__repeat (int) –

    how often the function is repeated: the result will be the sum of all: similar to the code below

    for repeat in range(profileit__repeat):
       profiler.enable()
       profiler.runcall(func, *func_positional_arguments, **func_keyword_arguments)
       profiler.disable()
    
  • benchmarkit__with_gc (bool) – if True gc is kept on during timing: if False: turns off garbage collection during the timing
  • benchmarkit__rank_by (str) – best or average
  • benchmarkit__run_sec (float or -1 or None) –

    the number of loops per run is scaled to approximately fit the benchmarkit__run_sec

    • if benchmarkit__run_sec is -1: then the generated function source code is only run once
    • if benchmarkit__run_sec is None: then the generated function source code is only printed
      this is mainly useful to see the exact final func code block which will be timed.
  • benchmarkit__repeat (int) – how often everything is repeated again This is a convenience variable that calls the whole setup repeatedly
Returns:

ready to print or write to file: table format is conform with reStructuredText

Return type:

str

3.1.6. SpeedIT.ProfileIT module

Profile module

SpeedIT.ProfileIT.speedit_profile(func_dict, use_func_name=True, output_in_sec=False, profileit__max_slashes_fileinfo=2, profileit__repeat=1)

Returns one txt string for: table format is conform with reStructuredText

Parameters:
  • func_dict (dict) – mapping function names to functions value format: tuple (function, list_of_positional_arguments, dictionary_of_keyword_arguments)
  • use_func_name (bool) – if True the function name will be used in the output name if False the func_dict key will be used in the the output name
  • output_in_sec (int) – if true the output is keep in seconds if false it is transformed to: second (s) millisecond (ms) One thousandth of one second microsecond (µs) One millionth of one second nanosecond (ns) One billionth of one second
  • profileit__max_slashes_fileinfo (int) – to adjust max path levels in the profile info
  • profileit__repeat (int) –

    how often the function is repeated: the result will be the sum of all: similar to the code below

    for repeat in range(profileit__repeat):
       profiler.enable()
       profiler.runcall(func, *func_positional_arguments, **func_keyword_arguments)
       profiler.disable()
    
Returns:

ready to print or write to file: table format is conform with reStructuredText

  • rank: starts with the part which takes the longest
  • compare: % of the total execution time
  • func_time: the total time spent in the given function (and excluding time made in calls to sub-functions)
  • number_of_calls: the number of calls
  • func_txt: provides the respective data of each function

Return type:

str

3.1.7. SpeedIT.ProjectErr module

Project Error

exception SpeedIT.ProjectErr.Err(error_type, info)

Bases: builtins.Exception

Prints an own raised ProjectError

Parameters:
  • errorType (str) – Error type: to specify mostly from which part the error comes: e.g. CONFIG
  • info (str) – text info to print as message

3.1.8. SpeedIT.Utils module

Diverse Helper functions

SpeedIT.Utils.format_time(time_)

Returns a formatted time string in the Orders of magnitude (time)

Parameters:time – if -1.0 return ‘NOT-MEASURED’‘
Returns:formatted time: Orders of magnitude (time) second (s) millisecond (ms) One thousandth of one second microsecond (µs) One millionth of one second nanosecond (ns) One billionth of one second
Return type:str
SpeedIT.Utils.get_table_max_columns_width(table, column_mapping)

Returns a list with columns width

Parameters:
  • table (list) – of dictionaries must correspond to column_mapping
  • column_mapping (list) –

    of tuples: mapping of final table column names to actual table keys

    column_mapping = [
       ('name', 'name'),
       ('rank', 'rank'),
       ('avg_loop_time', 'avg_loop_time_best_run'),
       ('all_runs_avg_loop', 'all_runs_avg_loop_time')
    ]
    
Returns:

of integers - columns widths

Return type:

list

SpeedIT.Utils.get_table_rst_formatted_lines(table, header_mapping, title_line='')

Returns list of table lines: format is conform with reStructuredText

Parameters:
  • table (list) – of dictionaries keys: must correspond to header_mapping
  • header_mapping (list) –

    of tuples: mapping of final table header names to actual table keys

    header_mapping = [
       ('name', 'name'),
       ('rank', 'rank'),
       ('avg_loop_time', 'avg_loop_time_best_run'),
       ('all_runs_avg_loop', 'all_runs_avg_loop_time')
    ]
    
  • title_line (str) – an optional string for a title line
Returns:

table lines: format is conform with reStructuredText

Return type:

list

3.1.9. SpeedIT.Version module

Version And Diverse Info

Module CONSTANTS:

__version__ str - the released version (last release)

RELEASE_DATE str - the date of the last release

SHORT_VERSION str - the main version is the: __version__ stripped of the last part: e.g. used by sphinx conf.py

TESTED_HOST_OS str - Keeps track of the HOST SYSTEM used to develop/test

__title__ str -

__copyright__ str -

__license__ str -

__author__ str -

3.1.10. Module contents

(c) 2014 peter1000 https://github.com/peter1000 All Rights Reserved

SpeedIT is distributed under the terms of the BSD 3-clause license. Consult LICENSE.rst or http://opensource.org/licenses/BSD-3-Clause.