All Projects → ramonsaraiva → Timy

ramonsaraiva / Timy

Licence: mit
Minimalist measurement of python code time

Programming Languages

python
139335 projects - #7 most used programming language

Labels

Projects that are alternatives of or similar to Timy

dogma
Things and stuffs.
Stars: ✭ 22 (-91.94%)
Mutual labels:  time
nepali-datetime
Python's core datetime inspired nepali datetime (BS date & NPT) package 🇳🇵
Stars: ✭ 36 (-86.81%)
Mutual labels:  time
NTP
NTP library for Arduino framework
Stars: ✭ 20 (-92.67%)
Mutual labels:  time
appointment-picker
Appointment Picker - a tiny JavaScript timepicker that helps you pick appointments
Stars: ✭ 49 (-82.05%)
Mutual labels:  time
iota
Miniature delta time and time dilation library for GameMaker Studio 2.3.2
Stars: ✭ 19 (-93.04%)
Mutual labels:  time
date4j
Lightweight alternative to Java's built-in date-time classes. Android-friendly. Compiles under JDK 1.5.
Stars: ✭ 36 (-86.81%)
Mutual labels:  time
macos-receiver
A MacOS TabBar (StatusBar) application that securely receives one-time passwords (OTPs) that you tapped in Raivo for iOS.
Stars: ✭ 44 (-83.88%)
Mutual labels:  time
Javascript Time Ago
International highly customizable relative date/time formatting
Stars: ✭ 263 (-3.66%)
Mutual labels:  time
goot
👋 Goot humanize greetings.
Stars: ✭ 14 (-94.87%)
Mutual labels:  time
edtf.js
Extended Date Time Format (ISO 8601-2 / EDTF) Parser for JavaScript
Stars: ✭ 44 (-83.88%)
Mutual labels:  time
finql
A quantitative finance toolbox
Stars: ✭ 21 (-92.31%)
Mutual labels:  time
OmniList
开源的时间管理App,基于Material Design设计
Stars: ✭ 61 (-77.66%)
Mutual labels:  time
clock
High-resolution clock functions: monotonic, realtime, cputime.
Stars: ✭ 52 (-80.95%)
Mutual labels:  time
native-app
🍿 🕐 🎞 React Native App for the PCT environment
Stars: ✭ 39 (-85.71%)
Mutual labels:  time
WatchKitTimePicker
⏱ A Time Picker data source for WatchKit that mirrors the behavior of UIDatePicker.
Stars: ✭ 37 (-86.45%)
Mutual labels:  time
humanize time
Adds the humanize method to reports the approximate distance in time between two Time. humanize supports i18n translations too so it can be used in internationalized apps.
Stars: ✭ 20 (-92.67%)
Mutual labels:  time
dayjs
Extended fork of Day.js - 2KB immutable date library alternative to Moment.js
Stars: ✭ 36 (-86.81%)
Mutual labels:  time
Md Date Time Picker
An implementation of Material Design Picker components in vanilla CSS, JS, and HTML
Stars: ✭ 272 (-0.37%)
Mutual labels:  time
react-ago-component
A component for React that renders the approximate time ago in words from a specific past date using an HTML5 time element.
Stars: ✭ 25 (-90.84%)
Mutual labels:  time
date-php
这是一个Javascript模仿PHP日期时间格式化函数,使用方法和PHP非常类似,有丰富的模板字符,并在原来的基础上增加了一些模板字符。 This is a date function that implement PHP in Javascript. It is very similar to PHP, has rich template characters, and enhances some template characters on the basis of the original.
Stars: ✭ 24 (-91.21%)
Mutual labels:  time

timy

Python 3.4 Python 3.5 Python 3.6 Python 3.7

CircleCI Codecov

Minimalist measurement of python code time

timy comes with a different idea of the built-in module timeit. It adds flexibility and different ways of measuring code time, using simple context managers and function decorators.

Installing

pip install timy

Usage

Decorating a function

Let's say you have a calculate function and you want to keep track of its execution time

import timy

@timy.timer()
def calculate(n, r):
    """
    Divide, multiply and sum 'n' to every number in range 'r'
    returning the result list
    """
    return [i / n * n + n for i in range(r)]

Whenever you call that function, the execution time will be tracked

calculate(5, 10000000)
>> Timy executed (calculate) for 1 time(s) in 1.529540 seconds
>> Timy best time was 1.529540 seconds

Changing the ident and adding loops to the execution

import timy

@timy.timer(ident='My calculation', loops=10)
def calculate(n, r):
    return [i / n * n + n for i in range(r)]
    
calculate(5, 10000000)
>> My calculation executed (calculate) for 10 time(s) in 15.165313 seconds
>> My calculation best time was 1.414186 seconds

Tracking specific points along your code

The with statement can also be used to measure code time

Named tracking points can be added with the track function

import timy

with timy.Timer() as timer:
    N = 10000000
    for i in range(N):
        if i == N/2:
            timer.track('Half way')
            
>> Timy (Half way) 0.557577 seconds
>> Timy 0.988087 seconds            

Another usage of tracking in a prime factors function

def prime_factors(n):
    with timy.Timer('Factors') as timer:
        i = 2
        factors = []
        def add_factor(n):
            factors.append(n)
            timer.track('Found a factor')

        while i * i <= n:
            if n % i == 0:
                add_factor(i)
                n //= i
            else:
                i += 1
        return factors + [n]

factors = prime_factors(600851475143)
print(factors)

>> Factors (Found a factor) 0.000017 seconds
>> Factors (Found a factor) 0.000376 seconds
>> Factors (Found a factor) 0.001547 seconds
>> Factors 0.001754 seconds
>> [71, 839, 1471, 6857]

Configuring

Importing timy config

from timy.settings import timy_config

Enable or disable timy trackings

You can enable or disable timy trackings with the tracking value.

The default value of tracking is True

timy_config.tracking = False

Changing the way timy outputs information

You can choose between print or logging for all timy outputs by setting the value of tracking_mode.

The default value of tracking_mode is TrackingMode.PRINTING.

from timy.settings import (
    timy_config,
    TrackingMode
)

timy_config.tracking_mode = TrackingMode.LOGGING

timy logs at the INFO level, which is not printed or stored by default. To configure the logging system to print all INFO messages do

import logging
logging.basicConfig(level=logging.INFO)

or to configure the logging system to print only timy's INFO messages do

import logging
logging.basicConfig()
logging.getLogger('timy').level=logging.INFO

Contribute

Contributions are always welcome, but keep it simple and small.

License

This project is licensed under the MIT License - see the LICENSE file for details

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].