Git Product home page Git Product logo

charvec's Introduction

#charvec: Benchmark character sequence random access Bart Massey 2022

In a Reddit comment user /u/pingveno proposed that accessing random characters of a UTF-8 string in Rust by iteration might be faster than accessing random elements of a Vec<char> even for small char sequences.

This weak microbenchmark tests this hypothesis. The benchmark is run separately over sequences of 7-bit ASCII characters and sequences of arbitrary Unicode code points. For each sequence type, a random sequence of length m is generated, then indexed 100,000,000 times at random positions in three ways: not at all ("baseline" condition), by indexing into a UTF-8 String ("string" condition), and by indexing into an array of Unicode char.

Care is taken to make the printed output a function of the input so that nothing is optimized out. Results are for my Debian Bullseye Linux box with a Ryzen 9 3900X processor.

Just a single representative run is shown. Changing PRNG seed and repeated runs gave identical results. Even changing PRNG gave comparable results.

ascii Time for 100,000,000 random accesses of m random ASCII characters.

unicode Time for 100,000,000 random accesses of m random Unicode code points.

As expected Vec<char> dominates String at longer sequence lengths. Slightly more surprisingly, it is not faster at any length.

Build And Run

  • cargo build --release
  • sh bench.sh >bench.txt (this will take a while)
  • sh graphs.sh

License

This work is available under the "MIT License". Please see the file LICENSE.txt in this distribution for license terms.

charvec's People

Contributors

bartmassey avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.