Skip to main content

A python library to measure algorithms execution time and compare with its theoretical complexity

Project description

Almetro Library

version number: 1.0.7 author: Arnour Sabino


A python library to measure algorithms execution time and compare with its theoretical complexity.

Build Status

Installation / Usage

To install use pip:

$ pip install almetro

Or clone the repo:

$ git clone
$ python install


Almetro uses timeit module from python to time your algorithms.

See more here


Applying Almetro to a quadratic algorithm:

import almetro
from almetro.algorithms import loop_n_quadratic
from almetro.complexity import cn_quadratic
from almetro.instance import growing

metro = almetro\
            .with_instances(instances=20, provider=growing(initial_size=100, growth_size=100))\
            .metro(algorithm=loop_n_quadratic, complexity=cn_quadratic)

chart = metro.chart()

Chart Almetro n quadratic

Applying Almetro to a lg n algorithm:

import almetro
from almetro.algorithms import loop_n_log
from almetro.complexity import clog_n
from almetro.instance import growing

metro = almetro\
            .with_instances(instances=20, provider=growing(initial_size=10000, growth_size=10000))\
            .metro(algorithm=loop_n_log, complexity=clog_n)

chart = metro.chart()

Chart Almetro lg n

Customazing execution:

import almetro
from almetro.complexity import Complexity
from almetro.instance import generator

my_custom_complexity = Complexity(
    theoretical=lambda v=1, e=1, c=1: v * v,
    experimental=lambda v=1, e=1, c=1: v + e,

# You need to provide instances as dict: {'name': '', 'size': {}, 'value': {}}
# Size must contains all needed theoretical complexity arguments
# Value must contain all needed algorithms arguments

def my_custom_instances(n):
    g = create_some_graph()
    for _ in range(n):
        yield {
            'name': 'my instance name',
            'size': {'v': len(g.nodes()), 'e': len(g.edges())}, 'c': some_order_value(),
            'value': {
                'graph': g,
                'v': len(g.nodes())

def my_custom_algorithm(graph, v):
    # Do some stuff

N = 50

instances_generator = my_custom_instances(N)

# Trials determine how many times each instance will be repeated for Almetro to pick the min time.
metro = almetro\
            .with_instances(instances=N, provider=generator(instances_generator)\
            .metro(algorithm=my_custom_algorithm, complexity=my_custom_complexity)


Chart Almetro v^2


Table Almetro v^2

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

almetro-1.0.7.tar.gz (11.3 kB view hashes)

Uploaded source

Built Distribution

almetro-1.0.7-py3-none-any.whl (11.8 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page