python method를 profile 하는 간단한 방법에 대한 소개
우선 decorator method를 정의한다. 그 뒤 profile 대상 메소드 def 위에 @profileit decorator를 붙인다.
import cProfile
def profileit(func):
def wrapper(*args, **kwargs):| # the algorithm is from https://stackoverflow.com/questions/16452383/how-to-get-all-24-rotations-of-a-3-dimensional-array | |
| import nunpy as np | |
| rollmat = np.array([[1, 0, 0], [0, 0, 1], [0, -1, 0]], dtype=np.float) | |
| turnmat = np.array([[0, -1, 0], [1, 0, 0], [0, 0, 1]], dtype=np.float) | |
| def get_24_rotation(): | |
| rotations = [] | |
| current_rot = np.eye(3) |
| import argparse | |
| def str2bool(v): | |
| if isinstance(v, bool): | |
| return v | |
| if v.lower() in ('yes', 'true', 't', 'y', '1'): | |
| return True | |
| elif v.lower() in ('no', 'false', 'f', 'n', '0'): | |
| return False | |
| else: |
| # usage : contries_flag_dict.get("<국가명>", "") | |
| contries_flag_dict = { | |
| "어센션 섬" : "🇦🇨", | |
| "안도라" : "🇦🇩", | |
| "아랍에미리트" : "🇦🇪", | |
| "아프가니스탄" : "🇦🇫", | |
| "앤티가 바부다" : "🇦🇬", | |
| "앵귈라" : "🇦🇮", | |
| "알바니아" : "🇦🇱", | |
| "아르메니아" : "🇦🇲", |
| i=1 | |
| sp="/-\|" | |
| echo -n ' ' | |
| while true | |
| do | |
| printf "\b${sp:i++%${#sp}:1}" | |
| sleep 0.1 | |
| done |
| #!/usr/bin/env python3 | |
| """Simple HTTP Server With Upload. | |
| This module builds on BaseHTTPServer by implementing the standard GET | |
| and HEAD requests in a fairly straightforward manner. | |
| see: https://gist.github.com/UniIsland/3346170 | |
| """ | |
| import sys | |
| import numpy as np | |
| data = np.random.uniform(-1, 1, [int(input("input random array length:"))]) | |
| data = np.around(data, 3).tolist() | |
| print(data) |
| import requests | |
| URL = 'http://www.tistory.com' | |
| response = requests.get(URL) | |
| print(response.status_code) | |
| print(response.text) |
| import sys | |
| from unicodedata import normalize | |
| import glob | |
| import os | |
| def nfd2nfc(data): | |
| return normalize('NFC', data) | |
| if len(sys.argv) > 1: | |
| dirname = sys.argv[1] |
| from unicodedata import normalize | |
| def nfd2nfc(data): | |
| return normalize('NFC', data) |