#!/usr/bin/env python3

import math
from funcy.debug import print_durations  
from funcy.debug import log_durations

# may need to be installed
# pip install funcy              (in virtual env)
# sudo apt install python3-funcy (system-wide)
# funcy -- functionaly Python

def useLogMessage(log_message):
  """do something with the log message, 
     like logging to a file"""
  print("# time logging: ", log_message)


@log_durations(useLogMessage)     # for any function call / block
# @print_durations()              # directly to console
def hardWork(nIter):
  xx = 0.0
  for _ in range(nIter):
    xx = 1.0/(1.0+xx) 
  return xx

golden = 0.5*(math.sqrt(5.0)-1)
# actually, the golden ratio is
#        0.5*(math.sqrt(5.0)+1)

print(hardWork(int(1e5)))
print(hardWork(int(1e7)))
print(golden)
