使用的是普通防爆pression比的IndexOf快? [英] Is using a Regular Expression faster than IndexOf?

查看:149
本文介绍了使用的是普通防爆pression比的IndexOf快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

这篇关于使用的是普通防爆pression比的IndexOf快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆