github.com/k14s/starlark-go@v0.0.0-20200720175618-3a5c849cc368/starlark/testdata/benchmark.star (about)

     1  # Benchmarks of Starlark execution
     2  # option:nesteddef
     3  
     4  def bench_range():
     5      return range(200)
     6  
     7  # Make a 2-level call tree of 100 * 100 calls.
     8  def bench_calling():
     9      list = range(100)
    10  
    11      def g():
    12          for x in list:
    13              pass
    14  
    15      def f():
    16          for x in list:
    17              g()
    18  
    19      f()
    20  
    21  # Measure overhead of calling a trivial built-in method.
    22  emptydict = {}
    23  range1000 = range(1000)
    24  
    25  def bench_builtin_method():
    26      for _ in range1000:
    27          emptydict.get(None)
    28  
    29  def bench_int():
    30      a = 0
    31      for _ in range1000:
    32          a += 1
    33  
    34  def bench_bigint():
    35      a = 1 << 31 # maxint32 + 1
    36      for _ in range1000:
    37          a += 1