High-level Abstractions, Safety, or Performance?
This project provides a source code for my talk at EPAM's Zed 2020 conference.
During the talk I compare safety, user experience, and performance of a similar scenario in 3 different programming languages: Java, Python, and C++. The discussed feature is the physical units library.
Libraries
- Java: JSR 385 - Units of Measurement
- Python: Pint
- C++: mp-units
Scenarios
-
Functional
- implement
avg_speed
function that takeslength
andtime
arguments and returnsspeed
in the unit derived from the units of function arguments - calculate
avg_speed(220 km, 2 h)
and print the result inkm/h
andm/s
- calculate
avg_speed(140 mi, 2 h)
and print the result inmi/h
andm/s
- implement
-
Safety
- ensure that for reordered arguments
avg_speed(2 h, 220 km)
returns an error - ensure that an error is reported when
avg_speed
returns the result of an invalid calculation- function multiplies the arguments instead of dividing them
- the result is not a quantity of speed
- ensure that for reordered arguments
-
Efficiency
- benchmark the following scenarios both for operations on fundamental/primitive types and on high-level
abstractions
- create the quantities of
length
andtime
and divide them to obtainspeed
- create a quantity of
speed
and convert the unit fromkm/h
tom/s
- create the quantities of
- check how much more memory is needed for a high-level abstraction (quantity class) compared to the fundamental/primitive magnitude type
- benchmark the following scenarios both for operations on fundamental/primitive types and on high-level
abstractions