为什么wcschr这么慢??? [英] why is wcschr so slow???

查看:103
本文介绍了为什么wcschr这么慢???的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为我的程序必须被循环捕获,并通过任务管理器的
取消它。在Java中花了大约一秒钟,但在

C中重新实现,它已经运行了一分钟。


我设置了一个调试器来显示每个循环的当前位置,让它运行
。它确实完成了,但花了20分钟。


我用我的程序中的wcschr替换了对这个替代品的调用:


静态WCHAR * altchr(注册WCHAR * s,注册WCHAR c){

而(TRUE)

{if(* s == c)

返回s;

如果(* s == 0)

返回0;

++ s;

}

}


现在我的程序立即完成,比Java版本更快,因为你可能期望
。 br />

wcschr做什么需要这么长时间???


我在XP上,使用Borland 5.5.1 C ++编译器可以从他们的网站上免费下载



解决方案



Albert Oppenheimer < SP ** @ spam.com>在消息中写道

新闻:e0 ********** @ geraldo.cc.utexas.edu ...

我以为我的程序必须是陷入循环,并通过任务管理器取消它。在Java中花了大约一秒钟,但是在
C中重新实现,它已经运行了一分钟。


C?你的意思是C ++,还是你在错误的新闻组?

我设置了一个调试器来显示每个循环的当前位置并让它运行。它确实达到了完成,但花了20分钟。

我在我的程序中调用了wcschr来调用这个
代替:

静态WCHAR * altchr (注册WCHAR * s,注册WCHAR c){
while(TRUE)
{if(* s == c)
return s;
if(* s == 0 )
返回0;
++ s;
}

现在我的程序立即完成,比Java版本更快,因为你可能会期待。

wcschr可以做什么需要这么长时间?

我在XP上,使用Borland 5.5.1 C ++编译器可以从他们的网站下载
免费




我在这里的参考书中没有看到任何功能。这是对strchr的Borland扩展吗?如果是这样,您可以询问他们(或在Borland

新闻组)关于他们实施

功能的任何性能问题。


也许他们的免费编译器值得每一分钱? :-)


或许你调用函数的方法(或你正在使用的数据)

与这种方式不能很好地工作他们设计了吗?他们会问的是,

我想。


-Howard



>我在这里的参考书中没有看到这个功能。它是一个

对strchr的Borland扩展吗?如果是这样,你可以问他们(或在borland
新闻组)关于他们实现该功能的任何性能问题。




wcschr是strchr的unicode版本。

它处理16位字符而不是8位字节。


上帝知道你使用的参考书。寻找标准的好地方

用于XP的C库函数(是的,我确实说这是在XP上)是在

http://msdn.microsoft.com/ library / de ... nipulation.asp


函数是C ++的基本函数,就像标准C表达式一样。


Albert Oppenheimer写道:
< blockquote class =post_quotes> wcschr是strchr的unicode版本。
它处理16位字符而不是8位字节。




调用这样的功能unicode版本是误导。


(不要责怪你 - 很多文档都有这个问题。但是我责备

你把wchar_t混淆为16位。有时候它更多!)


真正处理Unicode的函数将处理编码,例如

UTF-16,它将正确处理各种Unicode诡计,

如复合字符。


wcs函数不是;他们只是将每个wchar_t元素视为一个假设的字形。 (如果有的话我会很高兴知道,但我知道简单的

那些不是,所以wcschr()可能有资格。)


如果这个wcschr()确实正确地处理了Unicode,那么它可能会有点慢b / b
如果只是迭代wchar_t元素,然后它就没有理由让b $ b慢了,原版海报必须在别处查找问题。


-

Phlip
http://www.greencheese.org/ZeekLand < - 不是博客!!!


I thought my program had to be caught in a loop, and cancelled it through
the task manager. It took about one second in Java, but re-implemented in
C, it had already run over one minute.

I set up a debugger to display the current location each loop and let it
run. It did reach completion, but it took 20 minutes.

I replaced the calls to wcschr in my program with calls to this substitute:

static WCHAR* altchr(register WCHAR* s, register WCHAR c) {
while (TRUE)
{ if (*s == c)
return s;
if (*s == 0)
return 0;
++s;
}
}

Now my program finishes instantly, faster than the Java version, as you
might expect.

What could wcschr be doing that takes so long???

I''m on XP, using the Borland 5.5.1 C++ compiler that can be downloaded free
from their web site.

解决方案


"Albert Oppenheimer" <sp**@spam.com> wrote in message
news:e0**********@geraldo.cc.utexas.edu...

I thought my program had to be caught in a loop, and cancelled it through
the task manager. It took about one second in Java, but re-implemented in
C, it had already run over one minute.

C? Did you mean C++, or are you in the wrong newsgroup?
I set up a debugger to display the current location each loop and let it
run. It did reach completion, but it took 20 minutes.

I replaced the calls to wcschr in my program with calls to this
substitute:

static WCHAR* altchr(register WCHAR* s, register WCHAR c) {
while (TRUE)
{ if (*s == c)
return s;
if (*s == 0)
return 0;
++s;
}
}

Now my program finishes instantly, faster than the Java version, as you
might expect.

What could wcschr be doing that takes so long???

I''m on XP, using the Borland 5.5.1 C++ compiler that can be downloaded
free
from their web site.



I don''t see that function anywhere in my reference books here. Is it a
Borland extension to strchr? If so, you could ask them (or on a borland
newsgroup) about any performance issues with their implementation of that
function.

Perhaps their free compiler is worth every penny? :-)

Or perhaps your method of calling the function (or the data you''re using)
doesn''t work well with the way they desigend it? They''d be the ones to ask,
I think.

-Howard



> I don''t see that function anywhere in my reference books here. Is it a

Borland extension to strchr? If so, you could ask them (or on a borland
newsgroup) about any performance issues with their implementation of that
function.



wcschr is the unicode version of strchr.
It processes 16-bit characters instead of 8-bit bytes.

God knows what reference books you used. A good place to look for standard
C library functions for XP (yes, I did say this is on XP) is at

http://msdn.microsoft.com/library/de...nipulation.asp

Borland has the same standard C functions as Microsoft. And standard C
functions are basic to C++ just like standard C expressions.


Albert Oppenheimer wrote:

wcschr is the unicode version of strchr.
It processes 16-bit characters instead of 8-bit bytes.



Calling such a function "the unicode version" is misleading.

(Not to blame you - much documentation has this problem. But I _do_ blame
you for confusing wchar_t for 16-bits. Sometimes it''s more!)

A function that truly handles Unicode will handle an encoding, such as
UTF-16, and it will deal correctly with the various Unicode shenanigans,
such as composite characters.

The wcs functions don''t; they just treat each wchar_t element as one
hypothetical glyph. (If any do I''d be glad to know, but I know the simple
ones don''t, so wcschr() probably qualifies.)

If this wcschr() did indeed process Unicode correctly, it might be a little
slow.

If all it does is iterate over wchar_t elements, then it had no reason to be
slow, and the Original Poster must look elsewhere for the problem.

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!


这篇关于为什么wcschr这么慢???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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