Skip to content

Instantly share code, notes, and snippets.

@blazetopher
Created November 14, 2012 14:46
Show Gist options
  • Save blazetopher/4072534 to your computer and use it in GitHub Desktop.
Save blazetopher/4072534 to your computer and use it in GitHub Desktop.
coverage value insertion benchmark
def benchmark_value_sets(num_params=10, num_insertions=100):
# Instantiate a ParameterDictionary
pdict = ParameterDictionary()
# Create a set of ParameterContext objects to define the parameters in the coverage, add each to the ParameterDictionary
t_ctxt = ParameterContext('time', param_type=QuantityType(value_encoding=np.dtype('int64')))
t_ctxt.axis = AxisTypeEnum.TIME
t_ctxt.uom = 'seconds since 01-01-1970'
pdict.add_context(t_ctxt)
for i in xrange(num_params-1):
pdict.add_context(ParameterContext('param_{0}'.format(i)))
# Construct temporal and spatial Coordinate Reference System objects
tcrs = CRS([AxisTypeEnum.TIME])
scrs = CRS([AxisTypeEnum.LON, AxisTypeEnum.LAT])
# Construct temporal and spatial Domain objects
tdom = GridDomain(GridShape('temporal', [0]), tcrs, MutabilityEnum.EXTENSIBLE) # 1d (timeline)
sdom = GridDomain(GridShape('spatial', [0]), scrs, MutabilityEnum.IMMUTABLE) # 0d spatial topology (station/trajectory)
# Instantiate the SimplexCoverage providing the ParameterDictionary, spatial Domain and temporal Domain
cov = SimplexCoverage('test_data', create_guid(), 'empty sample coverage_model', pdict, tdom, sdom)
import time
full_time = time.time()
counter = 1
insert_times = []
cov.insert_timesteps(num_insertions)
for x in xrange(num_insertions):
in_time = time.time()
# cov.insert_timesteps(1)
slice_ = slice(cov.num_timesteps - 1, None)
cov.set_parameter_values('time', 1, tdoa=slice_)
for i in xrange(num_params-1):
cov.set_parameter_values('param_{0}'.format(i), 1.1, tdoa=slice_)
in_time = time.time() - in_time
insert_times.append(in_time)
counter += 1
print 'Average Insertion Time: %s' % (sum(insert_times) / len(insert_times))
print 'Full Time: %s' % (time.time() - full_time)
return cov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment