使用的是普通防爆pression比的IndexOf快?的是、普通、IndexOf、pression

2023-09-03 16:08:55 作者:傻瓜╮你是我的唯一

我有一个应用程序的运行,看起来在一个队列中的项目,然后根据特定关键字类别被施加 - 然后将其插入到一个数据库

I have an app running which looks at items in a queue, then based upon certain keywords a category is applied - then it is inserted into a database.

我使用的IndexOf确定某个关键字是present。

I'm using IndexOf to determine if a certain keyword is present.

这是理想的方法,或将一个正则表达式更快?

Is this the ideal way or would a RegEX be faster?

有每秒约10个项目正在处理左右。

There's about 10 items per second being processed or so.

推荐答案

对于刚刚找到一个关键字的的IndexOf 方法比使用常规EX pression更快。普通EX pressions是强大的,但他们的力量就在于灵活性,而不是原始速度。他们不打线方法,在简单的字符串操作。

For just finding a keyword the IndexOf method is faster than using a regular expression. Regular expressions are powerful, but their power lies in flexibility, not raw speed. They don't beat string methods at simple string operations.

总之,如果字符串不是很大,应该没有真正的问题,你不这样做的次数太多。

Anyway, if the strings are not huge, it shouldn't really matter as you are not doing it so often.

 
精彩推荐