Forum > Suggestions

CASE statement with strings.

<< < (5/6) > >>

winni:

--- Quote from: BeniBela on May 08, 2020, 01:11:20 am ---
It is like 4 times slower than other approaches

--- End quote ---

How much µ seconds?

Winni

lucamar:

--- Quote from: BeniBela on May 08, 2020, 01:11:20 am ---It is like 4 times slower than other approaches

--- End quote ---

That's quite logical; using a string-case is almost exactly as doing the long series of nested IFs, while the hash (or any other ordinal) CASE is optimized through jumptables and what-not.

Note, though, that AFAICS your test doesn't capture the time taken to calculate the hash from the strings; it might or might not be significant, depending on the hash method and the kind (and length) of the strings.

PascalDragon:

--- Quote from: BeniBela on May 07, 2020, 08:08:42 pm ---
--- Quote from: Remy Lebeau on May 07, 2020, 06:57:25 pm ---
The case with strings is equivalent to a series of if then else statements, no optimizations are performed.


--- End quote ---

Business as usual

A great idea and then a crap implementation

It should use a trie or at least a hashmap

--- End quote ---

It also needs to support ranges.

But hey, guess what, if you want you can provide patches to improve it.

It also does not yet support constant propagation (like the normal case-statement does).

BeniBela:

--- Quote from: winni on May 08, 2020, 02:08:09 am ---
How much µ seconds?


--- End quote ---

120 Nanoseconds each iteration !






--- Quote from: lucamar on May 08, 2020, 05:07:21 am ---That's quite logical; using a string-case is almost exactly as doing the long series of nested IFs, while the hash (or any other ordinal) CASE is optimized through jumptables and what-not.

--- End quote ---

The hash case also becomes a series of nested IFs. But an integer comparison is faster than a string comparison



--- Quote from: lucamar on May 08, 2020, 05:07:21 am ---Note, though, that AFAICS your test doesn't capture the time taken to calculate the hash from the strings; it might or might not be significant, depending on the hash method and the kind (and length) of the strings.

--- End quote ---

It tests both.

But that is on purpose, since I use it for HTML and calculate the hash for all HTML elements when loading the file



Nevertheless that is why I have a hunch that that a trie would perform better than a hash



--- Quote from: PascalDragon on May 08, 2020, 09:15:47 am ---It also needs to support ranges.

--- End quote ---

Is there really a need for ranges?


--- Quote from: PascalDragon on May 08, 2020, 09:15:47 am ---
But hey, guess what, if you want you can provide patches to improve it.


--- End quote ---

I already wrote a bye-coded trie for my Internet Tools. You could copy it

PascalDragon:

--- Quote from: BeniBela on May 08, 2020, 03:55:56 pm ---
--- Quote from: PascalDragon on May 08, 2020, 09:15:47 am ---It also needs to support ranges.

--- End quote ---

Is there really a need for ranges?
--- End quote ---

The normal case-statement supports ranges as well, thus case-of-string got support for that as well. This will not be removed.


--- Quote from: BeniBela on May 08, 2020, 03:55:56 pm ---
--- Quote from: PascalDragon on May 08, 2020, 09:15:47 am ---
But hey, guess what, if you want you can provide patches to improve it.


--- End quote ---

I already wrote a bye-coded trie for my Internet Tools. You could copy it

--- End quote ---

I'm not interested in optimizing case-of-string except maybe constant propagation.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version