Skip to content

Commit

Permalink
Tests: Added construct tests for generator expressions to check perfo…
Browse files Browse the repository at this point in the history
…rmance.
  • Loading branch information
kayhayen committed Dec 18, 2015
1 parent c961a77 commit 08a5018
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/benchmarks/constructs/GeneratorExit.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def generator():
except exc:
pass

return throw, exc


for x in xrange(50000):
calledRepeatedly()

Expand Down
45 changes: 45 additions & 0 deletions tests/benchmarks/constructs/GeneratorExpressionExit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2015, Kay Hayen, mailto:[email protected]
#
# Python test originally created or extracted from other peoples work. The
# parts from me are licensed as below. It is at least Free Softwar where
# it's copied from other people. In these cases, that will normally be
# indicated.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
def calledRepeatedly():
# We measure making a generator iterator step or not.
gen = (x for x in range(3))

next(gen)

# Take attribute lookup out of it, and built-in lookup too.
throw = gen.throw
exc = GeneratorExit

try:
# construct_begin
throw(exc)
# construct_alternative
pass
# construct_end
except exc:
pass

return throw, exc


for x in xrange(50000):
calledRepeatedly()

print("OK.")
35 changes: 35 additions & 0 deletions tests/benchmarks/constructs/GeneratorExpressionUsage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2015, Kay Hayen, mailto:[email protected]
#
# Python test originally created or extracted from other peoples work. The
# parts from me are licensed as below. It is at least Free Softwar where
# it's copied from other people. In these cases, that will normally be
# indicated.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

def calledRepeatedly():
# We measure making a generator iterator step or not.
gen = (x for x in range(3))

x = next(gen)
# construct_begin
next(gen)
# construct_end

return x

for x in xrange(50000):
calledRepeatedly()

print("OK.")
2 changes: 2 additions & 0 deletions tests/benchmarks/constructs/GeneratorUsage.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def generator():
next(gen)
# construct_end

return x

for x in xrange(50000):
calledRepeatedly()

Expand Down

0 comments on commit 08a5018

Please sign in to comment.