github.com/google/grumpy@v0.0.0-20171122020858-3ec87959189c/benchmarks/tuple.py (about)

     1  # Copyright 2016 Google Inc. All Rights Reserved.
     2  #
     3  # Licensed under the Apache License, Version 2.0 (the "License");
     4  # you may not use this file except in compliance with the License.
     5  # You may obtain a copy of the License at
     6  #
     7  #     http://www.apache.org/licenses/LICENSE-2.0
     8  #
     9  # Unless required by applicable law or agreed to in writing, software
    10  # distributed under the License is distributed on an "AS IS" BASIS,
    11  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  # See the License for the specific language governing permissions and
    13  # limitations under the License.
    14  
    15  """Benchmarks for list operations."""
    16  
    17  # pylint: disable=pointless-statement
    18  
    19  import weetest
    20  
    21  
    22  def BenchmarkTupleGetItem(b):
    23    l = (1, 3, 9)
    24    for _ in xrange(b.N):
    25      l[2]
    26  
    27  
    28  def BenchmarkTupleContains3(b):
    29    t = (1, 3, 9)
    30    for _ in xrange(b.N):
    31      9 in t
    32  
    33  
    34  def BenchmarkTupleContains10(b):
    35    t = tuple(range(10))
    36    for _ in xrange(b.N):
    37      9 in t
    38  
    39  
    40  if __name__ == '__main__':
    41    weetest.RunBenchmarks()