Test out deep clone strategies

Benchmark created on


Preparation HTML

<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js"></script>

Setup

const mockProviderMetadata = {
    provider_id: 1,
    external_id: "ext-123",
    sales_id: "sales-456",
    type: [undefined, null, undefined, 1, 3, "salut"],
    name: { en: "Provider Name", es: "Nombre del Proveedor" },
    email: "provider@example.com",
    owner_first_name: "John",
    owner_last_name: "Doe",
    owner_email: "john.doe@example.com",
    owner_phone: "123-456-7890",
    description: { en: "Description", es: "Descripción" },
    vendor_id: 789,
    vendor_name: "Vendor Name",
    city_id: 101,
    lat: 40.7128,
    lng: -74.0060,
    address: "123 Main St, New York, NY",
    place_id: "place-123",
    schedule: {
        0: [
            { start_at_minutes_from_midnight: 480, stop_at_minutes_from_midnight: 1020 }
        ],
        1: [
            { start_at_minutes_from_midnight: 480, stop_at_minutes_from_midnight: 1020 }
        ]
    },
    price_level: "medium",
    custom_delivery_radius_in_km: 10,
    status: "active",
    rating: 4.5,
    average_cooking_time: 30,
    phone: "123-456-7890",
    signup_source: "online",
    policies: {
        courier: {
            is_exclusive: true,
            provider_only_match_to_courier_ids: [1, 2, 3],
            provider_match_by_policy_ids: [4, 5, 6]
        },
        client: {
            provider_only_visible_to_client_ids: [7, 8, 9],
            supports_item_user_note: true,
            supports_order_user_note: true
        },
        robocall_config: {
            use_custom_settings: true,
            triggers: [
                "long",
                "dropped_polling"            ]
        },
        order: {
            auto_accept: {
                is_enabled: true
            }
        },
        cost_sharing: {
            version: "v1"
        },
        billing: {
            tax_withdrawing_eligible: true,
            two_accounts_invoicing: false
        }
    },
    currency: "USD",
    client_delivery_min_price: 20,
    client_delivery_min_price_distance_in_km: 5,
    client_delivery_surcharge_per_km: 2,
    min_order_price: 15,
    small_order_fee_cap: 5,
    is_promotion_enabled: true,
    promotion: { en: "Promotion", es: "Promoción" },
    courier_eta_threshold_alert_in_provider_app_in_seconds: 300,
    disable_estimation_correction: false,
    bypass_closing_mechanism: true,
    is_accepting_takeaway_orders: true,
    should_display_sku_in_provider_app: true,
    batching_config: {
        max_batch_size: 3,
        max_wait_time_in_minutes: 15
    },
    courier_pricing_config: {
        base_fee: 5,
        per_km_fee: 1
    },
    note_to_courier: { en: "Note to courier", es: "Nota para el mensajero" },
    commission: 10,
    commission_base: "base",
    takeaway_commission: 5,
    own_delivery_commission: 7,
    own_delivery_eta_in_minutes: 45,
    is_liable_to_vat: true,
    invoicing_account_iban: "IBAN123456",
    invoicing_account_recipient: "Recipient Name",
    invoicing_account_branch_code: "BRANCH123",
    invoicing_account_swift: "SWIFT123",
    invoicing_account_type: "Type",
    invoicing_is_payout_disabled: false,
    invoicing_payout_disabled_reason: "Reason",
    delivery_order_type: "standard",
    order_flow_settings: {
        allow_pre_order: true,
        pre_order_lead_time_in_minutes: 60
    },
    delivery_order_parallel_flow_type: "single",
    supported_delivery_type:"both",
    active_delivery_type:"delivery",
    cover_image_original_id: 123,
    cash_payments_accepted:"yes",
    website: "https://providerwebsite.com",
    hide_out_of_serving_interval_dishes_in_eater_app: false,
    can_self_assign_campaign: true,
    settings: {
        eater: {
            popular_items_tagging_settings: {
                is_automated_tagging_enabled: true,
                minimum_number_of_orders_to_compute_popularity: 10,
                should_use_popularity_for_ranking: true
            }
        }
    },
    menu_layout_in_eater_app:"grid",
    last_update: 1627849200,
    is_test: false,
    created: 1627849200,
    reg_code: "REG123",
    vat_code: "VAT123",
    should_send_client_food_cost_doc: true,
    billing_name: "Billing Name",
    billing_name_match: 1,
    billing_address: "123 Billing St, New York, NY",
    billing_address_match: 1,
    tax_registration_type:"business",
    tin_no: "TIN123",
    tin_no_validation_status:"valid",
    business_register_name: "Business Register Name"
};

Test runner

Ready to run.

Testing in
TestOps/sec
JSON.parse(JSON.stringify())
const parsed1 = JSON.parse(JSON.stringify(mockProviderMetadata));

console.log('parsed1', parsed1.type);
ready
structuredClone
const parsed2 = structuredClone(mockProviderMetadata);
console.log('parsed2', parsed2.type);
ready
lodash cloneDeep
const parsed3 = _.cloneDeep(mockProviderMetadata);
console.log('parsed3', parsed3.type);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.