Giter VIP home page Giter VIP logo

torbjorn's Introduction

Torbjorn

Pypi MIT License stars build

🔨 提供一些实用的 Python 装饰器~

Torbjorn(即托比昂)是守望先锋游戏中的英雄之一,他拥有一个强力输出的炮台。 俗话说「他强任他强,我用托比昂」,我希望本项目也能给你的 Python 代码提供强力的支持!

🎈️ v0.1.1:

使用 time.perf_counter 计算时间,以提高精准度。

安装

# pip 安装
pip install torbjorn

# or 源码安装
git clone https://github.com/Ailln/torbjorn.git
cd torbjorn && python setup.py install

使用

  • run_time: 计算运行时间
  • run_count: 计算运行次数
  • ctrl_c: 程序终止验证
import logging

import torbjorn as tbn


logger = logging.getLogger(__name__)


@tbn.run_time
@tbn.run_time(name="test_time")
@tbn.run_time(logger=logger, name="test_time")
@tbn.run_count
@tbn.run_count(name="test_count")
@tbn.run_count(logger=logger, name="test_count")
@tbn.ctrl_c
def calculate_million_numbers(num):
    number = 0
    for _ in range(num):
        number += 1


if __name__ == '__main__':
    for _ in range(10):
        calculate_million_numbers(1000000)
        
# output:
# [calculate_million_numbers] run count(t): 1
# [test_count] run count(t): 1
# [test_count] run count(t): 1
# [test_time] run time(s): 0.074010
# [test_time] run time(s): 0.074463
# [calculate_million_numbers] run time(s): 0.074512
# [calculate_million_numbers] run count(t): 2
# [test_count] run count(t): 2
# [test_count] run count(t): 2
# [test_time] run time(s): 0.074386
# [test_time] run time(s): 0.074522
# [calculate_million_numbers] run time(s): 0.074556
# ^CAre you sure to quit? (yes|y) / (no|n)
# >> 123
# ^CAre you sure to quit? (yes|y) / (no|n)
# >> no
# [calculate_million_numbers] run count(t): 3
# [test_count] run count(t): 3
# [test_count] run count(t): 3
# [test_time] run time(s): 0.072722
# [test_time] run time(s): 0.072863
# [calculate_million_numbers] run time(s): 0.072897
# ^CAre you sure to quit? (yes|y) / (no|n)
# >> yes
# >> exit...

许可

torbjorn's People

Contributors

ailln avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.