# file: cimport.py
#!usr/bin/python

import example, time

#Global variables
mystring = example.cvar.MyString
mydouble = example.cvar.MyDouble

#c-functions
cadd = example.cadd
caverage = example.caverage

x = 4.0
y = 2.0


print mystring

res = cadd(x,y)
print "Result: ", res

avg = caverage(x,y)
print "Average: ", avg

res = cadd(x,mydouble)
print "Result: ", res

avg = caverage(x,mydouble)
print "Average: ", avg


#define a python factorial function:
def fact(n):
	i = 1
	while n > 1:
		i = i * n
		n = n - 1
	return i

#which alternative is computationally most efficient (python-fact or c-fact)?
pyfact = fact
cfact = example.cfact

repetitions = 100000

c0 = time.clock()
for i in range(1,repetitions):
	pyfact(12)
cpu_time = time.clock()-c0

print "Python factorial, cpu-time: ", cpu_time


c0 = time.clock()
for i in range(1,repetitions):
	cfact(12)
cpu_time = time.clock()-c0

print "C factorial, cpu-time: ", cpu_time




