13.07.2015 Views

Analysis of Structures - Baustatik-Info-Server

Analysis of Structures - Baustatik-Info-Server

Analysis of Structures - Baustatik-Info-Server

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

2.12. DATE, TIME AND TIMESPAN Page 39# we need the datetime packagefrom datetime import datetime as time# calculating the timespan in floatsdef GetTimeSpanInSeconds(T):t = float(T.seconds)t+= float(T.microseconds)/1.e6t+= float(T.days)*24.*60.*60return tnX = 100000# number <strong>of</strong> entities to createT = () # empty tupleL = [] # empty list# create a tuple with nX itemst1 = time.now()for i in range(nX):T += (i,)t2 = time.now()sT = GetTimeSpanInSeconds(t2-t1) # and calculate the timespanprint "Creation <strong>of</strong> a tuple with %d items: %.3fs" % (nX,sT)# create a list with nX itemst1 = time.now()for i in range(nX):L += [i,]t2 = time.now()sL = GetTimeSpanInSeconds(t2-t1) # and calculate the timespanprint "creation <strong>of</strong> a list with %d items: %.3fs" % (nX,sL)# convert the list into a tuplet1 = time.now()TL = tuple(L)t2 = time.now()sTL= GetTimeSpanInSeconds(t2-t1) # and calculate the timespanprint "Create tuple from list: %.3fs" % sTLEnd <strong>of</strong> CodingThe console output on a one year old double processor notebook is given below. You see that it is verywasteful to create a tuple with a lot <strong>of</strong> items concatenating them with a += operator. On the other hand alist with the some number <strong>of</strong> items is created in no time. And the conversion <strong>of</strong> a list into a tuple costsnothing. So we can resume the the creation <strong>of</strong> a very large tuple should be done by creating a list and2.12.2011

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!