Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
옵션 가격 조회
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser:
Chrome 131
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
재귀
1623.3 Ops/sec
Stack
1825.0 Ops/sec
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
const createNestedOptions = (depth, breadth) => { if (depth === 0) { return { good_price: 10, good_qty: 1 }; } return { good_price: 10, good_qty: 1, option: Array(breadth) .fill(null) .map(() => createNestedOptions(depth - 1, breadth)), }; }; const sampleData = { good_price: 100, good_qty: 2, option: [createNestedOptions(10, 3)], // 깊이 10, 너비 3의 중첩된 옵션 };
Tests:
재귀
const orderProductTotalPrice = (product) => { const optionTotalPrice = (option) => { const optionPrice = option ? option.good_price * option.good_qty : 0; const childOptionPrice = option.option?.reduce((acc, cur) => { return acc + optionTotalPrice(cur); }, 0) || 0; return optionPrice + childOptionPrice; }; const { good_price, good_qty, option = [] } = product; const productPrice = Number(good_price) * Number(good_qty); const optionPrice = option.reduce((acc, cur) => { return acc + optionTotalPrice(cur); }, 0); return productPrice + optionPrice; }; orderProductTotalPrice(sampleData)
Stack
const orderProductTotalPrice = (product) => { const optionTotalPrice = (options) => { const stack = [...options]; // 옵션을 스택으로 초기화 let totalPrice = 0; while (stack.length > 0) { const currentOption = stack.pop(); if (currentOption) { totalPrice += currentOption.good_price * currentOption.good_qty; // 자식 옵션이 있으면 스택에 추가 if (currentOption.option) { stack.push(...currentOption.option); } } } return totalPrice; }; const { good_price, good_qty, option = [] } = product; const productPrice = Number(good_price) * Number(good_qty); const optionPrice = optionTotalPrice(option); return productPrice + optionPrice; }; orderProductTotalPrice(sampleData)