Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
FP vs OOP formatting implementation
(version: 1)
Comparing performance of:
OOP vs FP
Created:
10 months ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
const input = { price: '1234.567890' }; const locale = 'en-US'; const options = { style: 'currency', currency: 'USD' }; window.benchmarkConfig = { input, locale, options }
Tests:
OOP
class BaseFormatter { constructor(locale) { this.locale = locale; } formatPrice(input, options) { const rawValue = parseFloat(input); const formatter = new Intl.NumberFormat(this.locale, options); return formatter.format(rawValue); } } class OrderBookFormatter extends BaseFormatter { format(input) { return { price: this.formatPrice(input.price, window.benchmarkConfig.options), }; } } const oopFormatter = new OrderBookFormatter(window.benchmarkConfig.locale); oopFormatter.format(window.benchmarkConfig.input)
FP
const formatPrice = (input, { locale, options }) => { const rawValue = parseFloat(input); const formatter = new Intl.NumberFormat(locale, options); return formatter.format(rawValue); }; const createOrderBookFormatter = (locale) => { return (input) => { return { price: formatPrice(input.price, { locale, options: window.benchmarkConfig.options }), }; }; }; const fpFormatter = createOrderBookFormatter(window.benchmarkConfig.locale); fpFormatter(window.benchmarkConfig.input)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
OOP
FP
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
10 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36
Browser/OS:
Chrome 138 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
OOP
70981.3 Ops/sec
FP
78756.1 Ops/sec
Related benchmarks:
Number.toLocaleString vs Intl.NumberFormat3
Number.toLocaleString vs Intl.NumberFormat4
Number.toLocaleString vs Intl.NumberFormat5
Number.toLocaleString vs Intl.NumberFormat (prepared)
Number.toLocaleString vs Intl.NumberFormat memory pressure
Memoized Intl.NumberFormat vs fresh instances
cached Number.toLocaleString vs Intl.NumberFormat
Number.toLocaleString vs Intl.NumberFormat single instance
Number.toLocaleString vs Intl.NumberFormat single instance 2
Comments
Confirm delete:
Do you really want to delete benchmark?