• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2015 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5new BenchmarkSuite( 'With', [1000], [
6  new Benchmark('AccessOnSameLevel', false, false, 0,
7                AccessOnSameLevel, AccessOnSameLevelSetup,
8                AccessOnSameLevelTearDown),
9  new Benchmark('SetOnSameLevel', false, false, 0,
10                SetOnSameLevel, SetOnSameLevelSetup,
11                SetOnSameLevelTearDown),
12  new Benchmark('AccessOverPrototypeChain', false, false, 0,
13                AccessOverPrototypeChainSetup, AccessOverPrototypeChainSetup,
14                AccessOverPrototypeChainTearDown),
15  new Benchmark('CompetingScope', false, false, 0,
16                CompetingScope, CompetingScopeSetup, CompetingScopeTearDown)
17]);
18
19var objectUnderTest;
20var objectUnderTestExtended;
21var resultStore;
22var VALUE_OF_PROPERTY = 'Simply a string';
23var SOME_OTHER_VALUE = 'Another value';
24
25// ----------------------------------------------------------------------------
26
27function AccessOnSameLevelSetup() {
28  objectUnderTest = {first: VALUE_OF_PROPERTY};
29}
30
31function AccessOnSameLevel() {
32  with (objectUnderTest) {
33    resultStore = first;
34  }
35}
36
37function AccessOnSameLevelTearDown() {
38  return objectUnderTest.first === resultStore;
39}
40
41// ----------------------------------------------------------------------------
42
43function AccessOverPrototypeChainSetup() {
44  objectUnderTest = {first: VALUE_OF_PROPERTY};
45  objectUnderTestExtended = Object.create(objectUnderTest);
46  objectUnderTestExtended.second = 'Another string';
47}
48
49function AccessOverPrototypeChain() {
50  with (objectUnderTestExtended) {
51    resultStore = first;
52  }
53}
54
55function AccessOverPrototypeChainTearDown() {
56  return objectUnderTest.first === resultStore;
57}
58
59// ----------------------------------------------------------------------------
60
61function CompetingScopeSetup() {
62  objectUnderTest = {first: VALUE_OF_PROPERTY};
63}
64
65function CompetingScope() {
66  var first = 'Not correct';
67  with (objectUnderTest) {
68    resultStore = first;
69  }
70}
71
72function CompetingScopeTearDown() {
73  return objectUnderTest.first === resultStore;
74}
75
76// ----------------------------------------------------------------------------
77
78function SetOnSameLevelSetup() {
79  objectUnderTest = {first: VALUE_OF_PROPERTY};
80}
81
82function SetOnSameLevel() {
83  with (objectUnderTest) {
84    first = SOME_OTHER_VALUE;
85  }
86}
87
88function SetOnSameLevelTearDown() {
89  return objectUnderTest.first === SOME_OTHER_VALUE;
90}
91