Last active
January 14, 2022 14:01
-
-
Save zaro/e0fec52079bf0182f371d82ee90ca946 to your computer and use it in GitHub Desktop.
Map vs Set vs Object vs Array.find for loopups #jsbench #jsperf (http://jsbench.github.io/#e0fec52079bf0182f371d82ee90ca946) #jsbench #jsperf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"/> | |
<title>Map vs Set vs Object vs Array.find for loopups #jsbench #jsperf</title> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script> | |
<script src="./suite.js"></script> | |
</head> | |
<body> | |
<h1>Open the console to view the results</h1> | |
<h2><code>cmd + alt + j</code> or <code>ctrl + alt + j</code></h2> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
(function (factory) { | |
if (typeof Benchmark !== "undefined") { | |
factory(Benchmark); | |
} else { | |
factory(require("benchmark")); | |
} | |
})(function (Benchmark) { | |
var suite = new Benchmark.Suite; | |
Benchmark.prototype.setup = function () { | |
var DATA = [ | |
{ selection: "DataView_sfid"}, | |
{ selection: "DataView_api_id__c"}, | |
{ selection: "DataView_job_sfid"}, | |
{ selection: "DataView_job_api_id__c"}, | |
{ selection: "DataView_job_affiliate_id__c"}, | |
{ selection: "DataView_job_name"}, | |
{ selection: "DataView_job_import_id__c"}, | |
{ selection: "DataView_job_customer__c"}, | |
{ selection: "DataView_job_customer__r__api_id__c"}, | |
{ selection: "DataView_job_customer_second__c"}, | |
{ selection: "DataView_job_professional__c"}, | |
{ selection: "DataView_job_cgroup__c"}, | |
{ selection: "DataView_job_country__c"}, | |
{ selection: "DataView_job_eid__c"}, | |
{ selection: "DataView_job_invoicing_eid__c"}, | |
{ selection: "DataView_job_project_id__c"}, | |
{ selection: "DataView_job_company__c"}, | |
{ selection: "DataView_job_company2__c"}, | |
{ selection: "DataView_job_status__c"}, | |
{ selection: "DataView_job_owner__c"}, | |
{ selection: "DataView_job_createddate"}, | |
{ selection: "DataView_job_lastmodifieddate"}, | |
{ selection: "DataView_job_date_start__c"}, | |
{ selection: "DataView_job_date_end__c"}, | |
{ selection: "DataView_job_readiness_date__c"}, | |
{ selection: "DataView_job_date_expected__c"}, | |
{ selection: "DataView_job_appointment_customer_start__c"}, | |
{ selection: "DataView_job_appointment_customer_end__c"}, | |
{ selection: "DataView_job_price_selling__c"}, | |
{ selection: "DataView_job_price_purchasing__c"}, | |
{ selection: "DataView_job_price_lists_override__c"}, | |
{ selection: "DataView_job_price_selling_sum__c"}, | |
{ selection: "DataView_job_price_purchasing_sum__c"}, | |
{ selection: "DataView_job_price_lists__c"}, | |
{ selection: "DataView_job_professional_comment__c"}, | |
{ selection: "DataView_job_internal_comments__c"}, | |
{ selection: "DataView_job_referrer__c"}, | |
{ selection: "DataView_job_test_order__c"}, | |
{ selection: "cgroup_sfid"}, | |
{ selection: "cgroup_dokumentationstyp__c"}, | |
{ selection: "cgroup_name"}, | |
{ selection: "cgroup_invoicing_target__c"}, | |
{ selection: "cgroup_import_orders_as_new__c"}, | |
{ selection: "cgroup_external_id_type__c"}, | |
{ selection: "cgroup_default_days_for_delivery__c"}, | |
{ selection: "cgroup_email_type__c"}, | |
{ selection: "cgroup_assembly_time_days__c"}, | |
{ selection: "cgroup_accountid"}, | |
{ selection: "cgroup_readiness_date_required__c"}, | |
{ selection: "cgroup_test_cgroup__c"}, | |
{ selection: "cgroup_multiday__c"}, | |
{ selection: "cgroup_can_create_proposal"}, | |
{ selection: "cgroup_can_approve_proposal"}, | |
{ selection: "cgroup_can_pre_approve_proposal"}, | |
{ selection: "cgroup_approval_roles"}, | |
{ selection: "cgroup_customer_approval_target_status"}, | |
{ selection: "cgroup_default_product_supplier"}, | |
{ selection: "cgroup_due_days"}, | |
{ selection: "cgroup_purchase_order_number"}, | |
{ selection: "cgroup_product_order_condition"}, | |
{ selection: "cgroup_currency_tax_config_id"}, | |
{ selection: "cgroup_injected_communication_account_sfid"}, | |
{ selection: "cgroup_company_1"}, | |
{ selection: "cgroup_company_2"}, | |
{ selection: "currencyTaxConfig_id"}, | |
{ selection: "currencyTaxConfig_currency_symbol"}, | |
{ selection: "currencyTaxConfig_vat_rate"}, | |
{ selection: "company_sfid"}, | |
{ selection: "company_api_id__c"}, | |
{ selection: "company_recordtypeid"}, | |
{ selection: "company_persontitle"}, | |
{ selection: "company_salutation"}, | |
{ selection: "company_firstname"}, | |
{ selection: "company_lastname"}, | |
{ selection: "company_name"}, | |
{ selection: "company_companyname__c"}, | |
{ selection: "company_personemail"}, | |
{ selection: "company_emailforinvoices__c"}, | |
{ selection: "company_emailfororders__c"}, | |
{ selection: "company_phone"}, | |
{ selection: "company_personmobilephone"}, | |
{ selection: "company_some_factoring_target_enabled__c"}, | |
{ selection: "company_factoring_account__c"}, | |
{ selection: "company_umsatzsteuer_befreit__c"}, | |
{ selection: "company_iban__c"}, | |
{ selection: "company_bic__c"}, | |
{ selection: "company_accounting_per_job__c"}, | |
{ selection: "company_invoicerecipient__c"}, | |
{ selection: "company_language__c"}, | |
{ selection: "company_servicearea__c"}, | |
{ selection: "company_shippingstreet"}, | |
{ selection: "company_shippingpostalcode"}, | |
{ selection: "company_shippingcity"}, | |
{ selection: "company_shippingstate"}, | |
{ selection: "company_shippingstatecode"}, | |
{ selection: "company_shippingcountry"}, | |
{ selection: "company_shippingcountrycode"}, | |
{ selection: "company_shippinglatitude"}, | |
{ selection: "company_shippinglongitude"}, | |
{ selection: "company_billingstreet"}, | |
{ selection: "company_billingpostalcode"}, | |
{ selection: "company_billingcity"}, | |
{ selection: "company_billingstate"}, | |
{ selection: "company_billingstatecode"}, | |
{ selection: "company_billingcountry"}, | |
{ selection: "company_billingcountrycode"}, | |
{ selection: "company_billinglatitude"}, | |
{ selection: "company_billinglongitude"}, | |
{ selection: "company_1_sfid"}, | |
{ selection: "company_1_api_id__c"}, | |
{ selection: "company_1_recordtypeid"}, | |
{ selection: "company_1_persontitle"}, | |
{ selection: "company_1_salutation"}, | |
{ selection: "company_1_firstname"}, | |
{ selection: "company_1_lastname"}, | |
{ selection: "company_1_name"}, | |
{ selection: "company_1_companyname__c"}, | |
{ selection: "company_1_personemail"}, | |
{ selection: "company_1_emailforinvoices__c"}, | |
{ selection: "company_1_emailfororders__c"}, | |
{ selection: "company_1_phone"}, | |
{ selection: "company_1_personmobilephone"}, | |
{ selection: "company_1_some_factoring_target_enabled__c"}, | |
{ selection: "company_1_factoring_account__c"}, | |
{ selection: "company_1_umsatzsteuer_befreit__c"}, | |
{ selection: "company_1_iban__c"}, | |
{ selection: "company_1_bic__c"}, | |
{ selection: "company_1_accounting_per_job__c"}, | |
{ selection: "company_1_invoicerecipient__c"}, | |
{ selection: "company_1_language__c"}, | |
{ selection: "company_1_servicearea__c"}, | |
{ selection: "company_1_shippingstreet"}, | |
{ selection: "company_1_shippingpostalcode"}, | |
{ selection: "company_1_shippingcity"}, | |
{ selection: "company_1_shippingstate"}, | |
{ selection: "company_1_shippingstatecode"}, | |
{ selection: "company_1_shippingcountry"}, | |
{ selection: "company_1_shippingcountrycode"}, | |
{ selection: "company_1_shippinglatitude"}, | |
{ selection: "company_1_shippinglongitude"}, | |
{ selection: "company_1_billingstreet"}, | |
{ selection: "company_1_billingpostalcode"}, | |
{ selection: "company_1_billingcity"}, | |
{ selection: "company_1_billingstate"}, | |
{ selection: "company_1_billingstatecode"}, | |
{ selection: "company_1_billingcountry"}, | |
{ selection: "company_1_billingcountrycode"}, | |
{ selection: "company_1_billinglatitude"}, | |
{ selection: "company_1_billinglongitude"}, | |
{ selection: "company_2_sfid"}, | |
{ selection: "company_2_api_id__c"}, | |
{ selection: "company_2_recordtypeid"}, | |
{ selection: "company_2_persontitle"}, | |
{ selection: "company_2_salutation"}, | |
{ selection: "company_2_firstname"}, | |
{ selection: "company_2_lastname"}, | |
{ selection: "company_2_name"}, | |
{ selection: "company_2_companyname__c"}, | |
{ selection: "company_2_personemail"}, | |
{ selection: "company_2_emailforinvoices__c"}, | |
{ selection: "company_2_emailfororders__c"}, | |
{ selection: "company_2_phone"}, | |
{ selection: "company_2_personmobilephone"}, | |
{ selection: "company_2_some_factoring_target_enabled__c"}, | |
{ selection: "company_2_factoring_account__c"}, | |
{ selection: "company_2_umsatzsteuer_befreit__c"}, | |
{ selection: "company_2_iban__c"}, | |
{ selection: "company_2_bic__c"}, | |
{ selection: "company_2_accounting_per_job__c"}, | |
{ selection: "company_2_invoicerecipient__c"}, | |
{ selection: "company_2_language__c"}, | |
{ selection: "company_2_servicearea__c"}, | |
{ selection: "company_2_shippingstreet"}, | |
{ selection: "company_2_shippingpostalcode"}, | |
{ selection: "company_2_shippingcity"}, | |
{ selection: "company_2_shippingstate"}, | |
{ selection: "company_2_shippingstatecode"}, | |
{ selection: "company_2_shippingcountry"}, | |
{ selection: "company_2_shippingcountrycode"}, | |
{ selection: "company_2_shippinglatitude"}, | |
{ selection: "company_2_shippinglongitude"}, | |
{ selection: "company_2_billingstreet"}, | |
{ selection: "company_2_billingpostalcode"}, | |
{ selection: "company_2_billingcity"}, | |
{ selection: "company_2_billingstate"}, | |
{ selection: "company_2_billingstatecode"}, | |
{ selection: "company_2_billingcountry"}, | |
{ selection: "company_2_billingcountrycode"}, | |
{ selection: "company_2_billinglatitude"}, | |
{ selection: "company_2_billinglongitude"}, | |
{ selection: "customer_sfid"}, | |
{ selection: "customer_api_id__c"}, | |
{ selection: "customer_recordtypeid"}, | |
{ selection: "customer_persontitle"}, | |
{ selection: "customer_salutation"}, | |
{ selection: "customer_firstname"}, | |
{ selection: "customer_lastname"}, | |
{ selection: "customer_name"}, | |
{ selection: "customer_companyname__c"}, | |
{ selection: "customer_personemail"}, | |
{ selection: "customer_emailforinvoices__c"}, | |
{ selection: "customer_emailfororders__c"}, | |
{ selection: "customer_phone"}, | |
{ selection: "customer_personmobilephone"}, | |
{ selection: "customer_some_factoring_target_enabled__c"}, | |
{ selection: "customer_factoring_account__c"}, | |
{ selection: "customer_umsatzsteuer_befreit__c"}, | |
{ selection: "customer_iban__c"}, | |
{ selection: "customer_bic__c"}, | |
{ selection: "customer_accounting_per_job__c"}, | |
{ selection: "customer_invoicerecipient__c"}, | |
{ selection: "customer_language__c"}, | |
{ selection: "customer_servicearea__c"}, | |
{ selection: "customer_eid__c"}, | |
{ selection: "customer_order_intake_eid__c"}, | |
{ selection: "customer_shippingstreet"}, | |
{ selection: "customer_shippingpostalcode"}, | |
{ selection: "customer_shippingcity"}, | |
{ selection: "customer_shippingstate"}, | |
{ selection: "customer_shippingstatecode"}, | |
{ selection: "customer_shippingcountry"}, | |
{ selection: "customer_shippingcountrycode"}, | |
{ selection: "customer_shippinglatitude"}, | |
{ selection: "customer_shippinglongitude"}, | |
{ selection: "customer_billingstreet"}, | |
{ selection: "customer_billingpostalcode"}, | |
{ selection: "customer_billingcity"}, | |
{ selection: "customer_billingstate"}, | |
{ selection: "customer_billingstatecode"}, | |
{ selection: "customer_billingcountry"}, | |
{ selection: "customer_billingcountrycode"}, | |
{ selection: "customer_billinglatitude"}, | |
{ selection: "customer_billinglongitude"}, | |
{ selection: "customer_2_sfid"}, | |
{ selection: "customer_2_api_id__c"}, | |
{ selection: "customer_2_recordtypeid"}, | |
{ selection: "customer_2_persontitle"}, | |
{ selection: "customer_2_salutation"}, | |
{ selection: "customer_2_firstname"}, | |
{ selection: "customer_2_lastname"}, | |
{ selection: "customer_2_name"}, | |
{ selection: "customer_2_companyname__c"}, | |
{ selection: "customer_2_personemail"}, | |
{ selection: "customer_2_emailforinvoices__c"}, | |
{ selection: "customer_2_emailfororders__c"}, | |
{ selection: "customer_2_phone"}, | |
{ selection: "customer_2_personmobilephone"}, | |
{ selection: "customer_2_some_factoring_target_enabled__c"}, | |
{ selection: "customer_2_factoring_account__c"}, | |
{ selection: "customer_2_umsatzsteuer_befreit__c"}, | |
{ selection: "customer_2_iban__c"}, | |
{ selection: "customer_2_bic__c"}, | |
{ selection: "customer_2_accounting_per_job__c"}, | |
{ selection: "customer_2_invoicerecipient__c"}, | |
{ selection: "customer_2_language__c"}, | |
{ selection: "customer_2_servicearea__c"}, | |
{ selection: "customer_2_eid__c"}, | |
{ selection: "customer_2_order_intake_eid__c"}, | |
{ selection: "customer_2_shippingstreet"}, | |
{ selection: "customer_2_shippingpostalcode"}, | |
{ selection: "customer_2_shippingcity"}, | |
{ selection: "customer_2_shippingstate"}, | |
{ selection: "customer_2_shippingstatecode"}, | |
{ selection: "customer_2_shippingcountry"}, | |
{ selection: "customer_2_shippingcountrycode"}, | |
{ selection: "customer_2_shippinglatitude"}, | |
{ selection: "customer_2_shippinglongitude"}, | |
{ selection: "customer_2_billingstreet"}, | |
{ selection: "customer_2_billingpostalcode"}, | |
{ selection: "customer_2_billingcity"}, | |
{ selection: "customer_2_billingstate"}, | |
{ selection: "customer_2_billingstatecode"}, | |
{ selection: "customer_2_billingcountry"}, | |
{ selection: "customer_2_billingcountrycode"}, | |
{ selection: "customer_2_billinglatitude"}, | |
{ selection: "customer_2_billinglongitude"}, | |
{ selection: "partner_sfid"}, | |
{ selection: "partner_api_id__c"}, | |
{ selection: "partner_recordtypeid"}, | |
{ selection: "partner_persontitle"}, | |
{ selection: "partner_salutation"}, | |
{ selection: "partner_firstname"}, | |
{ selection: "partner_lastname"}, | |
{ selection: "partner_name"}, | |
{ selection: "partner_companyname__c"}, | |
{ selection: "partner_personemail"}, | |
{ selection: "partner_emailforinvoices__c"}, | |
{ selection: "partner_emailfororders__c"}, | |
{ selection: "partner_phone"}, | |
{ selection: "partner_personmobilephone"}, | |
{ selection: "partner_some_factoring_target_enabled__c"}, | |
{ selection: "partner_factoring_account__c"}, | |
{ selection: "partner_umsatzsteuer_befreit__c"}, | |
{ selection: "partner_iban__c"}, | |
{ selection: "partner_bic__c"}, | |
{ selection: "partner_accounting_per_job__c"}, | |
{ selection: "partner_invoicerecipient__c"}, | |
{ selection: "partner_language__c"}, | |
{ selection: "partner_servicearea__c"}, | |
{ selection: "partner_companytype__c"}, | |
{ selection: "partner_umsatzsteuerid__c"}, | |
{ selection: "partner_umsatzsteuer_befreit__c"}, | |
{ selection: "partner_shippingstreet"}, | |
{ selection: "partner_shippingpostalcode"}, | |
{ selection: "partner_shippingcity"}, | |
{ selection: "partner_shippingstate"}, | |
{ selection: "partner_shippingstatecode"}, | |
{ selection: "partner_shippingcountry"}, | |
{ selection: "partner_shippingcountrycode"}, | |
{ selection: "partner_shippinglatitude"}, | |
{ selection: "partner_shippinglongitude"}, | |
{ selection: "partner_billingstreet"}, | |
{ selection: "partner_billingpostalcode"}, | |
{ selection: "partner_billingcity"}, | |
{ selection: "partner_billingstate"}, | |
{ selection: "partner_billingstatecode"}, | |
{ selection: "partner_billingcountry"}, | |
{ selection: "partner_billingcountrycode"}, | |
{ selection: "partner_billinglatitude"}, | |
{ selection: "partner_billinglongitude"}, | |
{ selection: "services_quantity__c"}, | |
{ selection: "services_value_entry__c"}, | |
{ selection: "services_value_entry_measure__c"}, | |
{ selection: "services_single_selling_price__c"}, | |
{ selection: "services_single_purchase_price__c"}, | |
{ selection: "services_price_lists__c"}, | |
{ selection: "services_price_selling_sum__c"}, | |
{ selection: "services_price_purchasing_sum__c"}, | |
{ selection: "services_price_lists_sum__c"}, | |
{ selection: "services_is_active__c"}, | |
{ selection: "services_product_id__c"}, | |
{ selection: "services_invoicing_target__c"}, | |
{ selection: "services_sfid"}, | |
{ selection: "services_api_id__c"}, | |
{ selection: "services_name"}, | |
{ selection: "services_journey_to__c"}, | |
{ selection: "services_customer_needs__c"}, | |
{ selection: "services_tage_bis_zur_finalisierung_sla__c"}, | |
{ selection: "services_tech_support_url__c"}, | |
{ selection: "services_technischer_support__c"}, | |
{ selection: "services_installationsanleitung__c"}, | |
{ selection: "services_material__c"}, | |
{ selection: "services_werkzeug__c"}, | |
{ selection: "services_not_part_of_service__c"}, | |
{ selection: "services_vor__c"}, | |
{ selection: "services_unit_measure__c"}, | |
{ selection: "services_tags_enabled__c"}, | |
{ selection: "services_tags_mandatory__c"}, | |
{ selection: "services_is_remote__c"}, | |
{ selection: "services_async_appointment__c"}, | |
{ selection: "services_is_customer_sign_required__c"}, | |
{ selection: "services_is_planning__c"}, | |
{ selection: "services_block_position"}, | |
{ selection: "services_block_position_inner"}, | |
{ selection: "services_planning_service__c"}, | |
{ selection: "services_createddate"}, | |
{ selection: "services_sfj_job_sfid"}, | |
{ selection: "services_title_short_en__c"}, | |
{ selection: "services_title_short_de__c"}, | |
{ selection: "services_description_en__c"}, | |
{ selection: "services_description_de__c"}, | |
{ selection: "services_hints_en__c"}, | |
{ selection: "services_hints_de__c"}, | |
{ selection: "additionalItems_id"}, | |
{ selection: "additionalItems_link_id"}, | |
{ selection: "additionalItems_description"}, | |
{ selection: "additionalItems_quantity"}, | |
{ selection: "additionalItems_measure"}, | |
{ selection: "additionalItems_price_purchasing_sum"}, | |
{ selection: "additionalItems_price_selling_sum"}, | |
{ selection: "additionalItems_price_lists_sum"}, | |
{ selection: "additionalItems_price_purchasing"}, | |
{ selection: "additionalItems_price_selling"}, | |
{ selection: "additionalItems_price_lists"}, | |
{ selection: "additionalItems_invoicing_target"}, | |
{ selection: "additionalItems_created_at"}, | |
{ selection: "additionalItems_updated_at"}, | |
{ selection: "additionalItems_deleted_at"}, | |
{ selection: "additionalItems_job_api_id"}, | |
{ selection: "products_id"}, | |
{ selection: "products_product_id"}, | |
{ selection: "products_quantity"}, | |
{ selection: "products_supplier"}, | |
{ selection: "products_supplier_sfid"}, | |
{ selection: "products_invoicing_target"}, | |
{ selection: "products_price_purchasing"}, | |
{ selection: "products_price_selling"}, | |
{ selection: "products_price_listing"}, | |
{ selection: "products_job_api_id"}, | |
{ selection: "product_id"}, | |
{ selection: "product_name"}, | |
{ selection: "product_item_id"}, | |
{ selection: "product_price_purchasing_net"}, | |
{ selection: "product_price_selling_net"}, | |
{ selection: "product_price_listing"}, | |
{ selection: "product_ean"}, | |
{ selection: "product_description"}, | |
{ selection: "product_url"}, | |
{ selection: "product_vat"}, | |
{ selection: "product_oem_id"}, | |
{ selection: "product_product_type_id"}, | |
{ selection: "affiliate_sfid"}, | |
{ selection: "affiliate_api_id__c"}, | |
{ selection: "affiliate_recordtypeid"}, | |
{ selection: "affiliate_persontitle"}, | |
{ selection: "affiliate_salutation"}, | |
{ selection: "affiliate_firstname"}, | |
{ selection: "affiliate_lastname"}, | |
{ selection: "affiliate_name"}, | |
{ selection: "affiliate_companyname__c"}, | |
{ selection: "affiliate_personemail"}, | |
{ selection: "affiliate_emailforinvoices__c"}, | |
{ selection: "affiliate_emailfororders__c"}, | |
{ selection: "affiliate_phone"}, | |
{ selection: "affiliate_personmobilephone"}, | |
{ selection: "affiliate_some_factoring_target_enabled__c"}, | |
{ selection: "affiliate_factoring_account__c"}, | |
{ selection: "affiliate_umsatzsteuer_befreit__c"}, | |
{ selection: "affiliate_iban__c"}, | |
{ selection: "affiliate_bic__c"}, | |
{ selection: "affiliate_accounting_per_job__c"}, | |
{ selection: "affiliate_invoicerecipient__c"}, | |
{ selection: "affiliate_language__c"}, | |
{ selection: "affiliate_servicearea__c"}, | |
{ selection: "affiliate_shippingstreet"}, | |
{ selection: "affiliate_shippingpostalcode"}, | |
{ selection: "affiliate_shippingcity"}, | |
{ selection: "affiliate_shippingstate"}, | |
{ selection: "affiliate_shippingstatecode"}, | |
{ selection: "affiliate_shippingcountry"}, | |
{ selection: "affiliate_shippingcountrycode"}, | |
{ selection: "affiliate_shippinglatitude"}, | |
{ selection: "affiliate_shippinglongitude"}, | |
{ selection: "affiliate_billingstreet"}, | |
{ selection: "affiliate_billingpostalcode"}, | |
{ selection: "affiliate_billingcity"}, | |
{ selection: "affiliate_billingstate"}, | |
{ selection: "affiliate_billingstatecode"}, | |
{ selection: "affiliate_billingcountry"}, | |
{ selection: "affiliate_billingcountrycode"}, | |
{ selection: "affiliate_billinglatitude"}, | |
{ selection: "affiliate_billinglongitude"}, | |
{ selection: "productsPendingOrder_product_id"}, | |
{ selection: "productsPendingOrder_product_name"}, | |
{ selection: "productsPendingOrder_supplier_id"}, | |
{ selection: "productsPendingOrder_supplier_name"}, | |
{ selection: "productsPendingOrder_quantity"}, | |
{ selection: "productsPendingOrder_job_id"}, | |
{ selection: "jobTypes_job_api_id"}, | |
{ selection: "jobTypes_installation"}, | |
{ selection: "jobTypes_precheck"}, | |
{ selection: "jobTypes_activation"}, | |
{ selection: "jobTypes_remote"}, | |
{ selection: "jobTypes_hardware_sale"}, | |
{ selection: "jobTypes_maintenance"}, | |
{ selection: "jobTypes_planning"}, | |
{ selection: "jobTypes_customer_sign_required"}, | |
{ selection: "jobTypes_async_appointment"}, | |
{ selection: "jobTypes_id"}, | |
{ selection: "job_cgroup__c"}, | |
{ selection: "job_company__c"}, | |
{ selection: "company_1_id"}, | |
{ selection: "company_2_id"}, | |
{ selection: "job_affiliate__c"}, | |
{ selection: "job_customer__c"}, | |
{ selection: "job_customer_second__c"}, | |
{ selection: "job_professional__c"}, | |
{ selection: "api_id_for_project"}, | |
{ selection: "api_id_for_wallbox}"} | |
] | |
//DATA = DATA.slice(0, 50) | |
// ^2 | |
var DATA_OTHER= DATA.slice(0) | |
// // 1/10 | |
// var DATA_OTHER= DATA.slice(0, DATA.length/10 || 0) | |
console.log('DATA.lentgh=', DATA.length) | |
console.log('DATA_OTHER.lentgh=', DATA_OTHER.length) | |
//////////////////// | |
class ObjectArrayLookup { | |
constructor(array, key) { | |
this.array = array; | |
this.key = key; | |
if (this.array.length > ObjectArrayLookup.PRECOMPUTED_FIND_THRESHOLD) { | |
this.lookupSet = new Set(); | |
this.populateLookupSet(); | |
this.lookup = this.hasValue; | |
this.lookup2 = this.hasValue2; | |
} | |
else { | |
this.lookup = this.findValue; | |
this.lookup2 = this.findValue2; | |
} | |
} | |
populateLookupSet() { | |
for (const element of this.array) { | |
this.lookupSet.add(element[this.key]); | |
} | |
} | |
hasValue(value) { | |
return this.lookupSet.has(value); | |
} | |
hasValue2(value1, value2) { | |
return this.lookupSet.has(value1) || this.lookupSet.has(value1); | |
} | |
findValue(value) { | |
return this.array.find((element) => value === element[this.key]); | |
} | |
findValue2(value1, value2) { | |
return this.array.find((element) => value1 === element[this.key] || value2 === element[this.key]); | |
} | |
} | |
ObjectArrayLookup.PRECOMPUTED_FIND_THRESHOLD = 60; | |
}; | |
suite.add("Array.find", function () { | |
// Array.find | |
var i=0; | |
DATA_OTHER.forEach((e) => { | |
if(!DATA.find(select => select.selection === 'xxx' || select.selection === e.selection)) { | |
return; | |
} | |
i++ | |
}) | |
}); | |
suite.add("ObjectArrayLookup", function () { | |
// ObjectArrayLookup | |
var i=0; | |
const selects = new ObjectArrayLookup(DATA, "selection") | |
DATA_OTHER.forEach((e) => { | |
if(!selects.lookup2('xxx', e.selection)) { | |
return; | |
} | |
i++ | |
}) | |
}); | |
suite.add("Set (for of)", function () { | |
// Set (for of) | |
var i=0; | |
var selects =new Set(); | |
for(const e of DATA) { | |
selects.add(e.selection) | |
} | |
DATA_OTHER.forEach((e) => { | |
if(!selects.has('xxx') && !selects.has(e.selection)) { | |
return; | |
} | |
i++ | |
}) | |
}); | |
suite.add("Map (from iterable)", function () { | |
// Map (from iterable) | |
var i=0; | |
var selects =new Map(DATA.map(function (select) { return [select.selection, null] })); | |
DATA_OTHER.forEach((e) => { | |
if(!selects.has('xxx') && !selects.has(e.selection)) { | |
return; | |
} | |
i++ | |
}) | |
}); | |
suite.add("Object", function () { | |
// Object | |
var i=0; | |
var selects = Object.fromEntries(DATA.map(function (select) { return [select.selection, null]; })); | |
DATA_OTHER.forEach((e) => { | |
if(!('xxx' in selects) && !(e.selection in selects)) { | |
return; | |
} | |
i++ | |
}) | |
}); | |
suite.add("Set (forEach)", function () { | |
// Set (forEach) | |
var i=0; | |
var selects =new Set(); | |
DATA.forEach((e) => { | |
selects.add(e.selection) | |
}) | |
DATA_OTHER.forEach((e) => { | |
if(!selects.has('xxx') && !selects.has(e.selection)) { | |
return; | |
} | |
i++ | |
}) | |
}); | |
suite.add("Map (for of)", function () { | |
// Map (for of) | |
var i=0; | |
var selects =new Map(); | |
for(const e of DATA) { | |
selects.set(e.selection, null) | |
} | |
DATA_OTHER.forEach((e) => { | |
if(!selects.has('xxx') && !selects.has(e.selection)) { | |
return; | |
} | |
i++ | |
}) | |
}); | |
suite.add("Set (from iterable)", function () { | |
// Set (from iterable) | |
var i=0; | |
var selects =new Set(DATA.map(function (select) { return select.selection })); | |
DATA_OTHER.forEach((e) => { | |
if(!selects.has('xxx') && !selects.has(e.selection)) { | |
return; | |
} | |
i++ | |
}) | |
}); | |
suite.on("cycle", function (evt) { | |
console.log(" - " + evt.target); | |
}); | |
suite.on("complete", function (evt) { | |
console.log(new Array(30).join("-")); | |
var results = evt.currentTarget.sort(function (a, b) { | |
return b.hz - a.hz; | |
}); | |
results.forEach(function (item) { | |
console.log((idx + 1) + ". " + item); | |
}); | |
}); | |
console.log("Map vs Set vs Object vs Array.find for loopups #jsbench #jsperf"); | |
console.log(new Array(30).join("-")); | |
suite.run(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment