Debian Codegraph @

test/benchmark.py

raw
1 from cftime import num2date, date2num
2 try:
3 from time import perf_counter
4 except ImportError:
5 from time import clock as perf_counter
6 import numpy as np
7 units = 'hours since 01-01-01'
8 calendar = 'standard'
9 timevals = np.arange(0,10000,1)
10 print('processing %s values...' % len(timevals))
11 t1 = perf_counter()
12 dates =\
13 num2date(timevals,units=units,calendar=calendar,only_use_cftime_datetimes=True)
14 t2 = perf_counter()
15 t = t2-t1
16 print('num2date took %s seconds' % t)
17 timevals2 = date2num(dates,units=units,calendar=calendar)
18 t1 = perf_counter()
19 t = t1-t2
20 print('date2num took %s seconds' % t)