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:
one year ago
by:
Guest
Go 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:
one year 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
FP
79K/s
OOP
71K/s
View exact numbers
Test name
Executions per second
✓
FP
78,756 Ops/sec
OOP
70,981 Ops/sec
Related benchmarks
Number.toLocaleString vs Intl.NumberFormat4
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?