File: benchmark.py

package info (click to toggle)
cftime 1.6.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 388 kB
  • sloc: python: 1,922; sh: 23; makefile: 17
file content (20 lines) | stat: -rw-r--r-- 596 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from cftime import num2date, date2num
try:
    from time import perf_counter
except ImportError:
    from time import clock as perf_counter
import numpy as np
units = 'hours since 01-01-01'
calendar = 'standard'
timevals = np.arange(0,10000,1)
print('processing %s values...' % len(timevals))
t1 = perf_counter()
dates =\
num2date(timevals,units=units,calendar=calendar,only_use_cftime_datetimes=True)
t2 = perf_counter()
t = t2-t1
print('num2date took %s seconds' % t)
timevals2 = date2num(dates,units=units,calendar=calendar)
t1 = perf_counter()
t = t1-t2
print('date2num took %s seconds' % t)