From 7afa985f47ea9adb478226f0a32c4cdd194ed060 Mon Sep 17 00:00:00 2001 From: arai Date: Mon, 15 Feb 2016 17:51:49 +0900 Subject: [PATCH] Add map iterator to misc benchmark. --- benchmarks/misc/tests/assorted/LIST | 1 + .../misc/tests/assorted/misc-map-iterator.js | 57 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 benchmarks/misc/tests/assorted/misc-map-iterator.js diff --git a/benchmarks/misc/tests/assorted/LIST b/benchmarks/misc/tests/assorted/LIST index aa0f2e5..7ac30df 100644 --- a/benchmarks/misc/tests/assorted/LIST +++ b/benchmarks/misc/tests/assorted/LIST @@ -39,3 +39,4 @@ misc-bugs-1090583-dart2js-tracer misc-basic-hoist-bounds-check misc-apply-array misc-apply-array-headroom +misc-map-iterator diff --git a/benchmarks/misc/tests/assorted/misc-map-iterator.js b/benchmarks/misc/tests/assorted/misc-map-iterator.js new file mode 100644 index 0000000..f46ad08 --- /dev/null +++ b/benchmarks/misc/tests/assorted/misc-map-iterator.js @@ -0,0 +1,57 @@ +function assertEq(result, expected) { + if (result !== expected) + throw "Assertion: Expected " + expected + ", got " + result; +} + +var loops = 10000; +var entries = 100; + +var map = new Map(); +for (var i = 0; i < entries; i++) + map.set(i * 2, i * 3); + +function test_keys(m) { + for (var i = loops; i--;) { + var j = 0; + for (var k of m.keys()) { + assertEq(k, j * 2); + j++; + } + } +} +test_keys(map); + +function test_values(m) { + for (var i = loops; i--;) { + var j = 0; + for (var v of m.values()) { + assertEq(v, j * 3); + j++; + } + } +} +test_values(map); + +function test_entries(m) { + for (var i = loops; i--;) { + var j = 0; + for (var e of m.entries()) { + assertEq(e[0], j * 2); + assertEq(e[1], j * 3); + j++; + } + } +} +test_entries(map); + +function test_iterator(m) { + for (var i = loops; i--;) { + var j = 0; + for (var e of m) { + assertEq(e[0], j * 2); + assertEq(e[1], j * 3); + j++; + } + } +} +test_iterator(map);