Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
옵션 가격 조회
(version: 1)
Comparing performance of:
재귀 vs Stack
Created:
one year ago
by:
Guest
Jump to the latest result
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)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
재귀
Stack
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
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/OS:
Chrome 131 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
재귀
1623.3 Ops/sec
Stack
1825.0 Ops/sec
Related benchmarks:
Multiple Nil checks 0.1
Multiple Nil checks 0.2
Multiple Nil checks 0.3
Multiple Nil checks 0.8
merge preformance compare
merge preformance compare 2
merge preformance compare 3
옵션 가격 조회 (재귀 vs Stack)
옵션 가격 조회 - v2
Comments
Confirm delete:
Do you really want to delete benchmark?