in reply to improving speed in ngrams algorithm

I would start with not asking the array all the time how big it is. It doesn't change, so cache that value. Replacing the ranges with classic for loops might speed things up. I doubt a substr based solution be any faster. This is simple enough to do it in C though, even for a novice. If it's really time critical I would write it as XS.


holli

You can lead your users to water, but alas, you cannot drown them.

Replies are listed 'Best First'.
Re^2: improving speed in ngrams algorithm
by karlgoethebier (Abbot) on Jun 11, 2019 at 19:33 UTC
    “...do it in C though, even for a novice. If it's really time critical I would write it as XS.“

    This statement is not good just crap, sorry. Because nothing with C/XS is simple for a novice. Best regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

    perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

      The OP didn't ask about "easy" but "speed".

      I'm sure there are already ready to use C programs for this available.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice