benchmarks(3)
π benchmarks π
okay so bestie, welcome to the benchmarks page from avr-libc (manual section 3, iykyk π«Ά). This is the page where the library tells you, like, roughly how much flash, stack and MCU clock time certain functions are gonna cost you. Numbers, vibes, receipts. Let's get into it. β¨
π NAME π
benchmarks β the benchmark lowdown. π
The results below can only give a rough estimate of the resources necessary for using certain library functions. And honestly? There is a number of factors which can both increase or reduce the effort required, so don't come for the numbers, they're doing their best:
- Expenses for preparation of operands and their stack are not considered. π
- In the table, the size includes all additional functions (for example, function to multiply two integers) but they are only linked from the library.
- Expenses of time of performance of some functions essentially depend on parameters of a call, for example,
qsort()is recursive, andsprintf()receives parameters in a stack. - Different versions of the compiler can give a significant difference in code size and execution time. For example, the
dtostre()function, compiled with avr-gcc 3.4.6, requires 930 bytes. After transition to avr-gcc 4.2.3, the size become 1088 bytes. π (glow-up or glow-down, you decide)
π¦ A few of libc functions π¦
The tea before the table, bestie:
- Avr-gcc version is 4.7.1.
- The size of function is given in view of all picked up functions.
- By default Avr-libc is compiled with
-mcall-prologuesoption. - In brackets the size without taking into account modules of a prologue and an epilogue is resulted.
- Both of the size can coincide, if function does not cause a prologue/epilogue. (twins! π―)
Units legend: Flash bytes, Stack bytes, MCU clocks.
Function Units Avr2 Avr25 Avr4
atoi ('12345') Flash bytes 82 (82) 78 (78) 74 (74)
Stack bytes 2 2 2
MCU clocks 155 149 149
atol ('12345') Flash bytes 122 (122) 118 (118) 118 (118)
Stack bytes 2 2 2
MCU clocks 221 219 219
dtostre (1.2345, s, 6, 0) Flash bytes 1116 (1004) 1048 (938) 1048 (938)
Stack bytes 17 17 17
MCU clocks 1247 1105 1105
dtostrf (1.2345, 15, 6, s) Flash bytes 1616 (1616) 1508 (1508) 1508 (1508)
Stack bytes 38 38 38
MCU clocks 1634 1462 1462
itoa (12345, s, 10) Flash bytes 110 (110) 102 (102) 102 (102)
Stack bytes 2 2 2
MCU clocks 879 875 875
ltoa (12345L, s, 10) Flash bytes 134 (134) 126 (126) 126 (126)
Stack bytes 2 2 2
MCU clocks 1597 1593 1593
malloc (1) Flash bytes 768 (712) 714 (660) 714 (660)
Stack bytes 6 6 6
MCU clocks 215 201 201
realloc ((void *)0, 1) Flash bytes 1284 (1172) 1174 (1064) 1174 (1064)
Stack bytes 18 18 18
MCU clocks 305 286 286
qsort (s, sizeof(s), 1, cmp) Flash bytes 1252 (1140) 1022 (912) 1028 (918)
Stack bytes 42 42 42
MCU clocks 21996 19905 17541
sprintf_min (s, '%d', 12345) Flash bytes 1224 (1112) 1092 (982) 1088 (978)
Stack bytes 53 53 53
MCU clocks 1841 1694 1689
sprintf (s, '%d', 12345) Flash bytes 1614 (1502) 1476 (1366) 1454 (1344)
Stack bytes 58 58 58
MCU clocks 1647 1552 1547
sprintf_flt (s, '%e', 1.2345) Flash bytes 3228 (3116) 2990 (2880) 2968 (2858)
Stack bytes 67 67 67
MCU clocks 2573 2311 2311
sscanf_min ('12345', '%d', &i) Flash bytes 1532 (1420) 1328 (1218) 1328 (1218)
Stack bytes 55 55 55
MCU clocks 1607 1446 1446
sscanf ('12345', '%d', &i) Flash bytes 2008 (1896) 1748 (1638) 1748 (1638)
Stack bytes 55 55 55
MCU clocks 1610 1449 1449
sscanf ('point,color', '%[a-z]', s) Flash bytes 2008 (1896) 1748 (1638) 1748 (1638)
Stack bytes 86 86 86
MCU clocks 3067 2806 2806
sscanf_flt ('1.2345', '%e', &x) Flash bytes 3464 (3352) 3086 (2976) 3070 (2960)
Stack bytes 71 71 71
MCU clocks 2497 2281 2078
strtod ('1.2345', &p) Flash bytes 1632 (1520) 1536 (1426) 1480 (1480)
Stack bytes 20 20 21
MCU clocks 1235 1177 1124
strtol ('12345', &p, 0) Flash bytes 918 (806) 834 (724) 792 (792)
Stack bytes 22 22 28
MCU clocks 956 891 794
π Math functions π
The table contains the number of MCU clocks to calculate a function with a given argument(s). The main reason of a big difference between Avr2 and Avr4 is a hardware multiplication. no cap, that's the whole plot twist. π
Function Avr2 Avr4
__addsf3 (1.234, 5.678) 113 108
__mulsf3 (1.234, 5.678) 375 138
__divsf3 (1.234, 5.678) 466 465
acos (0.54321) 4411 2455
asin (0.54321) 4517 2556
atan (0.54321) 4710 2271
atan2 (1.234, 5.678) 5270 2857
cbrt (1.2345) 2684 2555
ceil (1.2345) 177 177
cos (1.2345) 3387 1671
cosh (1.2345) 4922 2979
exp (1.2345) 4708 2765
fdim (5.678, 1.234) 111 111
floor (1.2345) 180 180
fmax (1.234, 5.678) 39 37
fmin (1.234, 5.678) 35 35
fmod (5.678, 1.234) 131 131
frexp (1.2345, 0) 42 41
hypot (1.234, 5.678) 1341 866
ldexp (1.2345, 6) 42 42
log (1.2345) 4142 2134
log10 (1.2345) 4498 2260
modf (1.2345, 0) 433 429
pow (1.234, 5.678) 9293 5047
round (1.2345) 150 150
sin (1.2345) 3353 1653
sinh (1.2345) 4946 3003
sqrt (1.2345) 494 492
tan (1.2345) 4381 2426
tanh (1.2345) 5126 3173
trunc (1.2345) 178 178
reminder bestie: these are estimates, not promises. Your compiler version, your call parameters, your whole setup can move these numbers around. Don't @ me. π
and that's the page, periodt. π«Ά this was Version 2.1.0, dated Sat Jan 29 2022 β love that for us. go forth and optimise, you absolute main character. β¨π
π¦ where this page comes from
- fedora 43: avr-libc 2.2.1-3.fc43 Β· BSD-3-Clause
- fedora 44: avr-libc 2.2.1-5.fc44 Β· BSD-3-Clause
- opensuse-leap 16.0: avr-libc 2.1.0-bp160.1.33 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms