Giter Site home page Giter Site logo

Comments (2)

veelo avatar veelo commented on August 17, 2024 2

Not likely. This is an interesting general D question, and it could be worth asking on the learn forum.

In principle, string switches have the potential to be just as fast as enum switches, if the compiler is able to compare pointers to strings in static memory. That is not always the case, and I don't think Pegged grammars is one of them, sadly. (It would be nice to experiment with generating parsers that use an enum instead of strings.) So if a jump table is not possible, a large if () else if () else … is generated, in which strings are compared.

String comparison can fail early: as soon as two characters differ, the strings cannot be equal. So if you have 24 sentences that all start with a different letter of the alphabet, every one of them can be differentiated by comparing just the first letter.

In your short example this is already the case, so I would expect that you will see no change in speed whatsoever.

If you have a very large grammar and are looking for ways to speed things up, you should first see if there is any left recursion in it (as that cannot be fully memoized). If you have a lot of time on your hands you could try modifying Pegged to generate enum based grammars; I would do it if I had the time.

from pegged.

enjoysmath avatar enjoysmath commented on August 17, 2024

from pegged.

Related Issues (20)

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.