import datetime, time

def read_csv( filename ):     results = []     with open( filename, 'r' ) as file:         for line in file:             line    = line.rstrip()             columns = line.split( ';' )             results.append( columns )     return results
start  = datetime.datetime.now() start_c = time.clock() result = read_csv( 'sample1.csv' ) end_c = time.clock() end    = datetime.datetime.now() print( "user time =", (end-start).total_seconds(), 's' )  print( "CPU time =", end_c-start_c, 's' )

from time import perf_counter_ns, process_time_ns from math import pi

def compute( x, y ):     from math import sin, cos     return sin(x) * cos(y)

pc1 = perf_counter_ns() pt1 = process_time_ns()

output = "C:/Temp/output.txt" with open( output, "w" ) as file:     n = 3000     for i in range( n+1 ):         x = pi * i / n         for j in range( n+1 ):             y = pi * j / n             f = compute( x, y )             file.write( F"{x};{y};{f}\n" )

pt2 = process_time_ns() pc2 = perf_counter_ns() print( "Process time    = ", ( pt2 - pt1 ) / 1000000000 ) print( "Process counter = ", ( pc2 - pc1 ) / 1000000000 )

from math import pi from logging  import ( basicConfig,                        DEBUG,                        getLogger,                        shutdown as StopLogging )

def compute( x, y ):     from math import sin, cos     return sin(x) * cos(y)

basicConfig( filename='example.log',              format   = "%(asctime)-15s;%(thread)d;%(levelname)s;%(filename)s;%(lineno)d;%(message)s",              level    = DEBUG )

output = "C:/Temp/output.txt" with open( output, "w" ) as file:     n = 3000     getLogger( "loop" ).debug( "before loop" )     for i in range( n+1 ):         x = pi * i / n         for j in range( n+1 ):             y = pi * j / n             f = compute( x, y )             file.write( F"{x};{y};{f}\n" )     getLogger( "loop" ).debug( "after loop" )     StopLogging()

def f(x):     import math     return math.cos(x) * x

def build( nb ):     step   = 1.0 / nb     result = []     for i in range( nb+1 ):         x = step * i         result.append( f(x) )     return result

nb     = 10000000 result = build( nb )

import math 
def f(x):     return math.cos(x) * x

def build( nb ):     step   = 1.0 / nb     result = []     for i in range( nb+1 ):         x = step * i         result.append( f(x) )     return result

nb     = 10000000 result = build( nb )

from math import cos 
def f(x):     return cos(x) * x

def build( nb ):     step   = 1.0 / nb     result = []     for i in range( nb+1 ):         x = step * i         result.append( f(x) )     return result

nb     = 10000000 result = build( nb )

def build( nb ):     step   = 1.0 / nb     result = []     addList = result.append     for i in range( nb+1 ):         x = step * i         addList( f(x) )     return result

def build( nb ):     step   = 1.0 / nb     result = []     addList = result.append     for i in range( nb+1 ):         addList( f(step*i) )     return result

def fib(n):     if n<2:         return n     return fib(n-1) + fib(n-2)
x = [ fib(i) for i in range( 35 ) ] print(x)

from functools import lru_cache as cache
@cache( maxsize=None ) def fib(n):     if n<2:         return n     return fib(n-1) + fib(n-2)
x = [ fib(i) for i in range( 35 ) ] print(x)

from math import cos, sin, pi 
def create1( values ):     with open( "concat1.txt", "w" ) as file:         for t in values:             text = ""             for i, x in enumerate( t ):                 if i != 0:                     text += ';'                 text += str( x )             file.write( text + '\n' )

def create2( values ):     with open( "concat2.txt", "w" ) as file:         for t in values:             file.write( ';'.join( map( str, t ) ) + '\n' )

def create3( values ):     with open( "concat3.txt", "w" ) as file:         for t in values:             file.write( "%d;%.16f;%.16f;%.16f\n" % t )

def create4( values ):     with open( "concat4.txt", "w" ) as file:         for t in values:             file.write( "{0};{1};{2};{3}\n".format( *t ) )

def create5( values ):     with open( "concat5.txt", "w" ) as file:         for i, x, c, s in values:             file.write( F"{i};{x};{c};{s}\n" )

n      = 1000000 step   = pi / n var    = [ ( i, step * i ) for i in range( n+1 ) ] values = [ ( i, x, cos(x), sin(x) ) for i, x in var ]
create1( values ) create2( values ) create3( values ) create4( values ) create5( values )