Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c NSRegularExpression的时间效率_Objective C_Regex_Performance_Nsregularexpression - Fatal编程技术网

Objective c NSRegularExpression的时间效率

Objective c NSRegularExpression的时间效率,objective-c,regex,performance,nsregularexpression,Objective C,Regex,Performance,Nsregularexpression,只是好奇。是否有人知道使用matchesForString:options:error方法的NSRegularExpression的时间效率?我已在线阅读了其他实现的效率,但尚未找到任何有关NSRegularExpression的具体信息 例如,给定正则表达式:\b(?:x1 | x2 |…xn)\b其中x1,x2…xn是一组n个不同的简单字母模式,该搜索的时间复杂度是多少?它完全取决于正则表达式的复杂度。有免费的Internet工具可以对正则表达式进行基准测试。它不会完美地映射到NSRegu

只是好奇。是否有人知道使用matchesForString:options:error方法的NSRegularExpression的时间效率?我已在线阅读了其他实现的效率,但尚未找到任何有关NSRegularExpression的具体信息


例如,给定正则表达式:
\b(?:x1 | x2 |…xn)\b
其中x1,x2…xn是一组n个不同的简单字母模式,该搜索的时间复杂度是多少?

它完全取决于正则表达式的复杂度。有免费的Internet工具可以对正则表达式进行基准测试。它不会完美地映射到NSRegularExpression实现,但真正重要的是数量级上的差异。不过,首先,您应该问问自己,这是否真的会成为应用程序中的瓶颈。如果没有,请使用最干净、最可维护的解决方案。在@CrimsonChris所说的基础上,直到出现性能问题为止,尽可能编写最清晰的代码。如果存在性能问题,请在仪器中检查,找出原因并进行修复。预先获取是一个巨大的时间损失,可以更好地利用。几乎所有的罪魁祸首都是意外的代码。