Skip to content

Commit aacdb0f

Browse files
committed
deploy: d3a70bd
1 parent 67c4764 commit aacdb0f

File tree

3 files changed

+61
-174
lines changed

3 files changed

+61
-174
lines changed

cppcon2025/cppcon_2025_slides.html

Lines changed: 58 additions & 108 deletions
Large diffs are not rendered by default.

cppcon2025/cppcon_2025_slides.md

Lines changed: 3 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -620,72 +620,9 @@ if (!needs_escape)
620620

621621
# Optimization #3: Fast Integer serialization
622622

623-
(`std::to_chars`)
624-
625-
```cpp
626-
while(number >= 10) {
627-
*write_pointer-- = char('0' + (number % 10));
628-
number /= 10;
629-
}
630-
*write_pointer = char('0' + number);
631-
```
632-
633-
Writing from the end
634-
635-
---
636-
637-
# Two digits at a time
638-
639-
```cpp
640-
while(number >= 100) {
641-
memcpy(write_pointer - 1, &decimal_table[(pv % 100)*2], 2);
642-
write_pointer -= 2;
643-
pv /= 100;
644-
}
645-
if(number >= 10) {
646-
*write_pointer-- = char('0' + (number % 10));
647-
number /= 10;
648-
}
649-
*write_pointer = char('0' + number);
650-
```
651-
652-
---
653-
654-
# Know where to start writing
655-
656-
- Useful to compute quickly the number of digits
657-
658-
```cpp
659-
template <typename number_type>
660-
int int_log2(number_type x) {
661-
return 63 - leading_zeroes(uint64_t(x) | 1);
662-
}
663-
664-
int fast_digit_count_64(uint64_t x) {
665-
static uint64_t table[] = {9,
666-
99,
667-
999,
668-
//...
669-
9999999999999999ULL,
670-
99999999999999999ULL,
671-
999999999999999999ULL,
672-
9999999999999999999ULL};
673-
int y = (19 * int_log2(x) >> 6);
674-
y += x > table[y];
675-
return y + 1;
676-
}
677-
```
678-
679-
---
680-
681-
# Could use SIMD if we wanted to
682-
683-
- Daniel Lemire, "Converting integers to decimal strings faster with AVX-512," in Daniel Lemire's blog, March 28, 2022, https://lemire.me/blog/2022/03/28/converting-integers-to-decimal-strings-faster-with-avx-512/.
684-
685-
---
686-
687-
# Does fast integer processing matter?
688-
623+
* Use the equivalent of `std::to_chars`
624+
* Could use SIMD if we wanted to
625+
* Daniel Lemire, "Converting integers to decimal strings faster with AVX-512," in Daniel Lemire's blog, March 28, 2022, https://lemire.me/blog/2022/03/28/converting-integers-to-decimal-strings-faster-with-avx-512/.
689626
* Replace fast digit count by naive approach based on `std::to_string`
690627
```cpp
691628
std::to_string(value).length();

cppcon2025/cppcon_2025_slides.pdf

-11.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)