<s> import sys <EOL> from django . conf import settings <EOL> if '<STR_LIT>' in sys . argv or settings . TEST_PERFORMANCE : <EOL> from django . test import TestCase <EOL> from django . core . urlresolvers import reverse <EOL> from rest_framework . renderers import JSONRenderer <EOL> from rest_framework_gis import serializers as gis_serializers <EOL> from contexttimer import Timer <EOL> from . models import Location <EOL> class TestRestFrameworkGisPerformance ( TestCase ) : <EOL> NUMBER_OF_LOCATIONS = <NUM_LIT> <EOL> def _create_data ( self ) : <EOL> """<STR_LIT>""" <EOL> locations = [ ] <EOL> name = '<STR_LIT>' <EOL> slug = '<STR_LIT>' <EOL> wkt = '<STR_LIT>' <EOL> for n in range ( <NUM_LIT:1> , self . NUMBER_OF_LOCATIONS ) : <EOL> locations . append ( Location ( name = name . format ( n ) , <EOL> slug = slug . format ( n ) , <EOL> geometry = wkt . format ( n ) ) ) <EOL> Location . objects . bulk_create ( locations ) <EOL> def test_geojson_performance ( self ) : <EOL> class PerfSerializer ( gis_serializers . GeoFeatureModelSerializer ) : <EOL> class Meta : <EOL> model = Location <EOL> geo_field = '<STR_LIT>' <EOL> self . _create_data ( ) <EOL> serializer = PerfSerializer ( Location . objects . all ( ) , many = True ) <EOL> with Timer ( ) as t : <EOL> JSONRenderer ( ) . render ( serializer . data ) <EOL> msg = '<STR_LIT>' '<STR_LIT>' . format ( self . NUMBER_OF_LOCATIONS , t . elapsed ) <EOL> print ( '<STR_LIT>' . format ( msg ) ) </s>
