diff --git a/doc/examples.html b/doc/examples.html index 0bf9463..da4fc04 100644 --- a/doc/examples.html +++ b/doc/examples.html @@ -39,6 +39,7 @@ Tests
  • Example 6: serialization
  • Example 7: performance comparison
  • Example 8: custom factory
  • +
  • Example 9: parallel tokenization
  • Example 1: basic usage

    @@ -257,6 +258,42 @@ The example shows how to write and use a custom factory class. This by Boost.Flyweight, so helping the user visualize factory usage patterns.

    +

    Example 9: parallel tokenization

    + +

    +See source code. +

    + +

    +The program loads a text file and tokenizes its contents into words (sequences of +alphabetic characters) using several threads in parallel to perform the task. +Words are stored as plain std::strings or using different +boost::flyweight configurations. +These are the results for +http://mattmahoney.net/dc/enwik9.zip +(a chunk of the Wikipedia 1,000 million bytes in size) with Visual Studio 2022 on +a Windows machine with an Intel Core i5-8265U CPU and 8 GB of RAM: +

    + +
    +         std::string, 1 thread(s): 141176630 words,   11.4551 s
    +         std::string, 8 thread(s): 141176630 words,   2.75682 s
    +   regular flyweight, 1 thread(s): 141176630 words,   19.2284 s
    +   regular flyweight, 8 thread(s): 141176630 words,   36.0344 s
    +concurrent flyweight, 1 thread(s): 141176630 words,   20.9516 s
    +concurrent flyweight, 8 thread(s): 141176630 words,   7.84129 s
    +
    + +

    +boost::flyweight<std::string> performs worse +in the parallelized scenario due to its class-wide locking upon flyweight +creation. +On the other hand, using +concurrent_factory +with no_locking and no_tracking achieves +a higher bandwidth under parallelization. +

    +