Speed vs Size, and speed won this time.

I have a function named match() that uses some globals and a PROGMEM data set generated by another sketch to read text one char at a time and match or fail the entered text to any of the key words (up to 255) up to when the last letter is entered. The total number of words does not load the process much, the match process follows links and makes a single trail through the data as letter by letter is processed.

I had wanted to make the data set tighter, almost 1/2 current size. Nice thought but it was fast when it was simple, there were too many extra steps to deal with mixed text and indexes that smaller needed.

What I have with 16 keywords chosen for demo purposes keeps up with 250000 baud when I give it a block of keywords copied from serial monitor output, fed into the entry line. A new char should arrive to the Arduino every 40 usecs.

Does anyone want the Table Maker and Speed Test sketches? The Maker lets you change the keywords.

Shure. I'd like to have a look at them. :slight_smile:

Okay, files attached.

The Match program match() function is how it gets used. It is a state machine with a global state. Your sketch can read and change that, set state to 0 to initialize an attempt to match a keyword.

The match() function returns 255 on not-matched or 0 - 254 as index of the keyword matched.

If you tear out the speed test and timeout you can enter crs through serial monitor as you want. If you toggle debug prints you will get some trace information. It’s an attempt to match a word spelled as it arrives with a set of known words. You can feed stored text a char at a time with a loop, read text on SD as a stream and get higher speed I’m sure.

The speed test reports micros() between serial reads. Serial monitor must be 250000 baud.

I block copied the keywords shown below using ctrl-c

TEST

memccpy
memchr
memcmp
memcpy
memmem
memmove
memrchr
memset
strcat
strchr
strcmp
strcpy
strlen
strlwr
strstr
strupr

Then I pasted them into the serial monitor enter line with ctrl-v, hit enter and it added this:

input char match-state matched keyword index or 255

TEST OUTPUT

0 m 0 255
44 e 1 255
40 m 1 255
40 c 1 255
36 c 1 255
48 p 1 255
40 y 1 0
40 32 2 0
40 m 0 255
40 e 1 255
40 m 1 255
36 c 1 255
40 h 1 255
40 r 1 1
40 32 2 1
44 m 0 255
36 e 1 255
40 m 1 255
40 c 1 255
44 m 1 255
36 p 1 2
36 32 2 2
44 m 0 255
40 e 1 255
36 m 1 255
48 c 1 255
40 p 1 255
40 y 1 3
36 32 2 3
44 m 0 255
36 e 1 255
40 m 1 255
40 m 1 255
40 e 1 255
40 m 1 4
40 32 2 4
40 m 0 255
40 e 1 255
36 m 1 255
52 m 1 255
32 o 1 255
40 v 1 255
40 e 1 5
40 32 2 5
40 m 0 255
44 e 1 255
40 m 1 255
40 r 1 255
32 c 1 255
48 h 1 255
40 r 1 6
40 32 2 6
40 m 0 255
40 e 1 255
40 m 1 255
36 s 1 255
40 e 1 255
40 t 1 7
36 32 2 7
44 s 0 255
36 t 1 255
48 r 1 255
40 c 1 255
40 a 1 255
40 t 1 8
36 32 2 8
44 s 0 255
36 t 1 255
40 r 1 255
40 c 1 255
44 h 1 255
44 r 1 9
36 32 2 9
32 s 0 255
48 t 1 255
40 r 1 255
40 c 1 255
36 m 1 255
36 p 1 10
48 32 2 10
32 s 0 255
48 t 1 255
40 r 1 255
40 c 1 255
40 p 1 255
36 y 1 11
40 32 2 11
40 s 0 255
40 t 1 255
40 r 1 255
36 l 1 255
44 e 1 255
36 n 1 12
40 32 2 12
44 s 0 255
36 t 1 255
48 r 1 255
36 l 1 255
44 w 1 255
40 r 1 13
40 32 2 13
40 s 0 255
40 t 1 255
40 r 1 255
36 s 1 255
48 t 1 255
36 r 1 14
40 32 2 14
40 s 0 255
40 t 1 255
40 r 1 255
36 u 1 255
40 p 1 255
40 r 1 15
36 32 2 15
44 32 0 15
40 10 0 15

My guess is that the speed test puts more load on the MCU than does the match process.

You can change the keywords and how many of them (255 max) with the table maker. Table maker serial output is source code for your own match() using app.

Dictionary_Match_1_Speed_Test.ino (6.99 KB)

Dictionary_Table_Maker_1.ino (8.17 KB)

Whandall:
Shure. I'd like to have a look at them. :slight_smile:

I'm starting up a user demo, BWD with user-serial-command and noticed a small bug in the table maker, it always makes the number of keys 16. I have code that fixes it but it's pretty easy to correct the error in the IDE after you paste Table Maker serial output into your sketch that uses match().

This will take a while.....