Monday, February 26, 2018

Find the speed limiting part of your Python code

Say you have a Python code, 'simple.py' like this:
import time
def func_A():
    time.sleep(1)
def func_B():
    time.sleep(10)
    
if __name__=='__mian__':
    func_A()
    func_B()
and you want to figure out which part takes the most time to finish. What you can do is:
python -m cProfile simple.py
However, the output is kinda too complicated to understand.
A better way is to use 'cprofilev', which you can install from here.
python -m cProfilev simple.py
Output would look like:
[cProfileV]: cProfile output available at http://127.0.0.1:4000
Just go to http://127.0.0.1:4000 and all the information are right there waiting for you.
## https://github.com/ymichael/cprofilev

Tuesday, February 6, 2018

Round to thousands | AWK

function rounding(var1){
    a = var1+500
    b = int(a/1000)
    return b
}

BEGIN{
    FS="|"
    OFS="|"
}
{   
     print $1,$2, $3, rounding($4), rounding($5), rounding($6), rounding($7), rounding($8),rounding($9),rounding($10),rounding($11),rounding($12)
}

my-alpine and docker-compose.yml

 ``` version: '1' services:     man:       build: .       image: my-alpine:latest   ```  Dockerfile: ``` FROM alpine:latest ENV PYTH...