add perf tests for different geometry complexities as well as all code branches for getmeasure
This commit is contained in:
parent
cbe7b6dd15
commit
463db99222
@ -8,14 +8,41 @@ from time import time
|
||||
USE_SCHEMA = True
|
||||
|
||||
for q in (
|
||||
'DROP TABLE IF EXISTS obs_censustest',
|
||||
'''CREATE TABLE obs_censustest (cartodb_id SERIAL PRIMARY KEY,
|
||||
the_geom GEOMETRY, name TEXT, measure NUMERIC, category TEXT)''',
|
||||
'''INSERT INTO obs_censustest (the_geom, name)
|
||||
SELECT * FROM {schema}OBS_GetBoundariesByGeometry(
|
||||
'DROP TABLE IF EXISTS obs_perftest_simple',
|
||||
'''CREATE TABLE obs_perftest_simple (cartodb_id SERIAL PRIMARY KEY,
|
||||
point GEOMETRY,
|
||||
geom GEOMETRY,
|
||||
offset_geom GEOMETRY,
|
||||
name TEXT, measure NUMERIC, category TEXT)''',
|
||||
'''INSERT INTO obs_perftest_simple (point, geom, offset_geom, name)
|
||||
SELECT ST_PointOnSurface(the_geom) point,
|
||||
the_geom geom,
|
||||
ST_Translate(the_geom, -0.1, 0.1) offset_geom,
|
||||
geom_refs AS name
|
||||
FROM (SELECT * FROM {schema}OBS_GetBoundariesByGeometry(
|
||||
st_makeenvelope(-74.05437469482422,40.66319159533881,
|
||||
-73.81885528564453,40.745696344339564, 4326),
|
||||
'us.census.tiger.block_group_clipped') As m(the_geom, geoid)'''
|
||||
'us.census.tiger.census_tract_clipped')) foo
|
||||
ORDER BY ST_NPoints(the_geom) ASC
|
||||
LIMIT 50''',
|
||||
'DROP TABLE IF EXISTS obs_perftest_complex',
|
||||
'''CREATE TABLE obs_perftest_complex (cartodb_id SERIAL PRIMARY KEY,
|
||||
point GEOMETRY,
|
||||
geom GEOMETRY,
|
||||
offset_geom GEOMETRY,
|
||||
name TEXT, measure NUMERIC, category TEXT)''',
|
||||
'''INSERT INTO obs_perftest_complex (point, geom, offset_geom, name)
|
||||
SELECT ST_PointOnSurface(the_geom) point,
|
||||
the_geom geom,
|
||||
ST_Translate(the_geom, -0.1, 0.1) offset_geom,
|
||||
geom_refs AS name
|
||||
FROM (SELECT * FROM {schema}OBS_GetBoundariesByGeometry(
|
||||
st_makeenvelope(-75.05437469482422,40.66319159533881,
|
||||
-73.81885528564453,41.745696344339564, 4326),
|
||||
'us.census.tiger.county_clipped')) foo
|
||||
ORDER BY ST_NPoints(the_geom) DESC
|
||||
LIMIT 50;''',
|
||||
'''SET statement_timeout = 5000;'''
|
||||
):
|
||||
query(q.format(
|
||||
schema='cdb_observatory.' if USE_SCHEMA else '',
|
||||
@ -24,37 +51,53 @@ for q in (
|
||||
|
||||
|
||||
ARGS = {
|
||||
'OBS_GetMeasureByID': "name, 'us.census.acs.B01001002', '{}'",
|
||||
'OBS_GetMeasure': "{}, 'us.census.acs.B01001002'",
|
||||
'OBS_GetCategory': "{}, 'us.census.spielman_singleton_segments.X10'",
|
||||
('OBS_GetMeasureByID', None): "name, 'us.census.acs.B01001002', '{}'",
|
||||
('OBS_GetMeasure', 'predenominated'): "{}, 'us.census.acs.B01003001'",
|
||||
('OBS_GetMeasure', 'area'): "{}, 'us.census.acs.B01001002', 'area'",
|
||||
('OBS_GetMeasure', 'denominator'): "{}, 'us.census.acs.B01001002', 'denominator'",
|
||||
('OBS_GetCategory', None): "{}, 'us.census.spielman_singleton_segments.X10'",
|
||||
}
|
||||
|
||||
GEOMS = {
|
||||
'point': 'ST_PointOnSurface(the_geom)',
|
||||
'polygon_match': 'the_geom',
|
||||
'polygon_buffered': 'ST_Buffer(the_geom::GEOGRAPHY, 1000)::GEOMETRY(GEOMETRY, 4326)',
|
||||
}
|
||||
|
||||
|
||||
@parameterized([
|
||||
('OBS_GetMeasureByID', 'us.census.tiger.block_group_clipped'),
|
||||
('OBS_GetMeasureByID', 'us.census.tiger.county'),
|
||||
('OBS_GetMeasure', GEOMS['point']),
|
||||
('OBS_GetMeasure', GEOMS['polygon_match']),
|
||||
('OBS_GetMeasure', GEOMS['polygon_buffered']),
|
||||
('OBS_GetCategory', GEOMS['point']),
|
||||
('OBS_GetCategory', GEOMS['polygon_match']),
|
||||
('OBS_GetCategory', GEOMS['polygon_buffered']),
|
||||
('simple', 'OBS_GetMeasureByID', None, 'us.census.tiger.census_tract'),
|
||||
('complex', 'OBS_GetMeasureByID', None, 'us.census.tiger.county'),
|
||||
|
||||
('simple', 'OBS_GetMeasure', 'predenominated', 'point'),
|
||||
('simple', 'OBS_GetMeasure', 'predenominated', 'geom'),
|
||||
('simple', 'OBS_GetMeasure', 'predenominated', 'offset_geom'),
|
||||
('simple', 'OBS_GetMeasure', 'area', 'point'),
|
||||
('simple', 'OBS_GetMeasure', 'area', 'geom'),
|
||||
('simple', 'OBS_GetMeasure', 'area', 'offset_geom'),
|
||||
('simple', 'OBS_GetMeasure', 'denominator', 'point'),
|
||||
('simple', 'OBS_GetMeasure', 'denominator', 'geom'),
|
||||
('simple', 'OBS_GetMeasure', 'denominator', 'offset_geom'),
|
||||
('simple', 'OBS_GetCategory', None, 'point'),
|
||||
('simple', 'OBS_GetCategory', None, 'geom'),
|
||||
('simple', 'OBS_GetCategory', None, 'offset_geom'),
|
||||
|
||||
('complex', 'OBS_GetMeasure', 'predenominated', 'point'),
|
||||
('complex', 'OBS_GetMeasure', 'predenominated', 'geom'),
|
||||
('complex', 'OBS_GetMeasure', 'predenominated', 'offset_geom'),
|
||||
('complex', 'OBS_GetMeasure', 'area', 'point'),
|
||||
('complex', 'OBS_GetMeasure', 'area', 'geom'),
|
||||
('complex', 'OBS_GetMeasure', 'area', 'offset_geom'),
|
||||
('complex', 'OBS_GetMeasure', 'denominator', 'point'),
|
||||
('complex', 'OBS_GetMeasure', 'denominator', 'geom'),
|
||||
('complex', 'OBS_GetMeasure', 'denominator', 'offset_geom'),
|
||||
('complex', 'OBS_GetCategory', None, 'point'),
|
||||
('complex', 'OBS_GetCategory', None, 'geom'),
|
||||
('complex', 'OBS_GetCategory', None, 'offset_geom'),
|
||||
])
|
||||
def test_performance(api_method, arg):
|
||||
print api_method, arg
|
||||
def test_performance(geom_complexity, api_method, normalization, geom):
|
||||
print api_method, geom_complexity, normalization, geom
|
||||
col = 'measure' if 'measure' in api_method.lower() else 'category'
|
||||
for rows in (1, 10, 50, 100):
|
||||
q = 'UPDATE obs_censustest SET {col} = {schema}{api_method}({args}) WHERE cartodb_id < {n}'.format(
|
||||
for rows in (1, 5, 10, ):
|
||||
q = 'UPDATE obs_perftest_{complexity} SET {col} = {schema}{api_method}({args}) WHERE cartodb_id < {n}'.format(
|
||||
col=col,
|
||||
complexity=geom_complexity,
|
||||
schema='cdb_observatory.' if USE_SCHEMA else '',
|
||||
api_method=api_method,
|
||||
args=ARGS[api_method].format(arg),
|
||||
args=ARGS[api_method, normalization].format(geom),
|
||||
n=rows+1)
|
||||
start = time()
|
||||
query(q)
|
||||
|
Loading…
Reference in New Issue
Block a user