Timeline for What is the optimal way to perform 5000 unique string replace functions in terms of performance?
Current License: CC BY-SA 4.0
12 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Dec 3, 2018 at 18:54 | comment | added | Anon |
The before strings in my case are fairly controlled but were hypothetically vulnerable to your example (No longer, as I built in hash logic which uses whole strings as keys, and replaces it with the matching value). In essence, I have built an interpreter that operates upon wikipedia templates. While it was possible to supply something like {{foobar|PANDNK}} , wikipedia itself would have thrown an error, because the parameter would not have been valid. Now even if that is the case, PANDNK would not have matched the hash and would sent me a warning, leaving it uninterpreted.
|
|
Dec 3, 2018 at 9:26 | comment | added | gnasher729 | If the input is “PANDNK”, your code will replace it with “PAndorra NK” and not “Panama Denmark “. Is that intentional? You really need to say something about your input data, because many good suggestions will change the output in this case. | |
Jul 16, 2018 at 16:03 | comment | added | R. Schmitz | @Akiva "happy with my speed" vs. "cut a few hours (daily?) off my processing time"? I think you need some of the boring, but necessary work of formalizing what you're doing. You need some hard condition, like "max 5 sec/iteration". A point where you can say it was successful - or not possible. If you're just "improving" your code, it will eat up your valuable time like nothing. Also, get busy with a profiler. It's always a bit annoying to learn a new tool, but profilers will be quick, once-in-a-lifetime and it will improve your improving so much. | |
Jul 16, 2018 at 15:18 | comment | added | Teimpz | @Akiva you should do is check if a significant portion of execution time is actually spent calling this replace function and not somewhere else. | |
Jul 16, 2018 at 14:55 | history | edited | Deduplicator | CC BY-SA 4.0 |
added syntax-highlighting
|
Jul 15, 2018 at 5:28 | answer | added | hocho | timeline score: 4 | |
Jul 14, 2018 at 23:13 | answer | added | Blrfl | timeline score: 6 | |
Jul 14, 2018 at 22:32 | comment | added | Anon |
@DanMills but is it actually a significant performance bottleneck? -- No; I am happy with my speed. At most, I might do 10000 strings in a day, which probably averages about 10 seconds per iteration, and replacing probably comprises no more than 50% of that. I am surprised my code runs as fast as it does, However it would be nice if I could cut a few hours off my processing time.
|
|
Jul 14, 2018 at 21:39 | answer | added | Aphton | timeline score: 1 | |
Jul 14, 2018 at 21:36 | answer | added | amon | timeline score: 2 | |
Jul 14, 2018 at 21:24 | comment | added | Dan Mills | What you have is ugly, but is it actually a significant performance bottleneck? My instinct says that while I would be doing something data driven, probably involving iterating over a list of substitutions (Read in from file at startup) and calling s.replace for each possibility, the actual performance hit for doing this dumb and stupid for a few hundred substitutions is probably negligible in the scheme of things. Don't get clever unless profiling says you have a real problem. | |
Jul 14, 2018 at 20:29 | history | asked | Anon | CC BY-SA 4.0 |