4月30日晚上8:52,某人 < someb ... @ cox.netwrote:On Apr 30, 8:52 pm, "Somebody" <someb...@cox.netwrote: < cpun ... @ gmail.comwrote in message 新闻:11 ********************** @ n76g2000hsh.googlegr oups.com ......<cpun...@gmail.comwrote in messagenews:11**********************@n76g2000hsh.googlegr oups.com... 4月30日晚上8:24,有人 < someb ... @ cox.netwrote: On Apr 30, 8:24 pm, "Somebody" <someb...@cox.netwrote: < snip><snip> 字符串库可能是你的编译器固有的,并且 strcmp可以解释为什么可以在字符串结束之前比较a时的多个字节。你可能会更快地写一个内联函数找到一个字符串中的第一个数字,然后 strcmp数字之前的字节,然后你做内联 比较数字 the string library is probably intrinsic with your compiler, and strcmp works off the knowledge that one can compare multiple bytes at a time before the end of the string. it may be faster for you to write an inlined function that finds the first number in a string, then strcmp the bytes previous to the numbers, and then do your inlined compare of the numbers 嗯... 我确实想到做某事像这样,但即使我上面给出的示例字符串 是很好......它并不总是那样。想象一下,如果 你有类似DVD-ISO9817-FULLIMAGE-1-07-2005的东西。举个例子。我要 必须单独比较字符串的每个字符串段并跟踪 我在哪里。我认为这会有更多的开销。 又一次......是的,看起来有一个strcmp的固有形式与 Visual Studio 2005, *但*内部函数在调试模式下被禁用。 在内在之前: strcmp花了6688 StrCmpLogical花了139640 内在后: strcmp花了2188 StrCmpLogical花了139609Hmm...I did think of doing something like that, but even though the example stringI gave above was "nice"... it isn''t always going to be that way. Imagine ifyou have something like "DVD-ISO9817-FULLIMAGE-1-07-2005" as an example. I''dhave to compare every string segment of the string seperately and keep trackof where I''m at. I thought it would be more overhead.Hmm again... yeah, it looks like there is an intrinsic form of strcmp withVisual Studio 2005, *BUT* intrinsic functions are disabled in debug mode.Before intrinsics:strcmp took 6688StrCmpLogical took 139640After intrinsics:strcmp took 2188StrCmpLogical took 139609 嗯,仅从你的例子来看,似乎你的代码比strcmp要复杂得多,因此*应该*采取 显着更长。虽然我仍然无法解释额外的 开销......也许是ASM与C / C ++调用约定?试试__fastcall?hmmm, just judging from your example, it seems that your code issignificantly more complicated than strcmp, and hence *should* takesignificantly longer. though i still cant explain the extraoverhead... ASM vs C/C++ calling convention, perhaps? try __fastcall? 这篇关于为什么这段代码这么慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-19 13:52
查看更多