| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- "use strict";
- // benchmark ways to test if var is in a known set
- // setup
- var name = "things",
- arr = ["foo", "bar", "baz", "qux", "stuff", "things"],
- obj = {foo:"foo", bar:"bar", baz:"baz", qux:"qux", stuff:"stuff", things:"things"};
- // tests
- exports.knownSetHas = {
- "array indexOf, ref": function() {
- return arr.indexOf(name) !== -1;
- },
- "array indexOf, inline": function() {
- return ["foo", "bar", "baz", "qux", "stuff", "things"].indexOf(name) !== -1;
- },
- "object in, closure": function() {
- return name in obj;
- },
- "object in, inline": function() {
- return name in {foo:"foo", bar:"bar", baz:"baz", qux:"qux", stuff:"stuff", things:"things"};
- },
- "switch, inline": function() {
- switch (name) {
- case "foo":
- case "bar":
- case "baz":
- case "qux":
- case "stuff":
- case "things":
- return true;
- default:
- return false;
- }
- },
- "if, inline": function() {
- return name === "foo" ||
- name === "bar" ||
- name === "baz" ||
- name === "qux" ||
- name === "stuff" ||
- name === "things";
- },
- };
- // if run directly run benchmarks
- if (!module.parent) require("benchmarksman").runner(exports);
|