将byte []转换为值的性能 [英] Performance to convert byte[] to a value

查看:67
本文介绍了将byte []转换为值的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将字节[]复制到诸如

long之类的值时,有什么方法可以获得最佳性能?

我使用

BitConverter.ToInt64(二进制,偏移)

但性能不够好。在我的情况下,我需要有最好的性能



What is the way to have best performance to copy a byte[] to a value such as
long?
I use
BitConverter.ToInt64(binary, offset)
But the performace is not good enough. I need to have the best performance
in my case.

推荐答案

Roy写道:
Roy wrote:

将byte []复制到诸如

long之类的值时,有什么方法可以获得最佳性能?

我使用

BitConverter.ToInt64(二进制,偏移)

但是性能不够好。在我的情况下,我需要有最好的性能


What is the way to have best performance to copy a byte[] to a value such as
long?
I use
BitConverter.ToInt64(binary, offset)
But the performace is not good enough. I need to have the best performance
in my case.



你知道一些关于你将拥有的字节的东西吗?与微软编码的一般情况相比,它们是特殊的吗? />

如果不是,我发现很难相信它可能会更快找到更好的东西。


哦 - 你确定这真的是你的应用程序的瓶颈吗?


(你应该能够每秒做1到2亿转换)


Arne

Do you know something about the bytes you will have that makes them
special compared to the general case Microsoft has coded for ?

If not I find it difficult to believe that it will be possible
to find something faster.

Oh - and are you sure this is really the bottleneck in your app ??

(you should be able to do 100-200 million conversions per second)

Arne


5月4日,8:23 * am,Arne Vajh?j< a ... @ vajhoej.dkwrote:
On May 4, 8:23*am, Arne Vajh?j <a...@vajhoej.dkwrote:

Roy写道:
Roy wrote:

将byte []复制到值的最佳性能是什么?比如

多长?

我用

BitConverter.ToInt64(二进制,偏移)

但是性能是还不够好。在我的情况下,我需要有最好的性能


What is the way to have best performance to copy a byte[] to a value such as
long?
I use
BitConverter.ToInt64(binary, offset)
But the performace is not good enough. I need to have the best performance
in my case.



你知道一些关于你将拥有的字节的东西吗?与微软编码的一般情况相比,这是特殊的
?br />

如果不是,我发现很难相信它可能会更快找到更好的东西。


哦 - 你确定这真的是你的应用程序的瓶颈吗?


(你应该能够每秒做1到2亿转换)


Arne


Do you know something about the bytes you will have that makes them
special compared to the general case Microsoft has coded for ?

If not I find it difficult to believe that it will be possible
to find something faster.

Oh - and are you sure this is really the bottleneck in your app ??

(you should be able to do 100-200 million conversions per second)

Arne



根据我的理解,BIrConverter是将字节

数组转换为数字的apt选项。它有一个属性来检查字节顺序 -

IsLittleEndian。不知道从perdormance点来看有多糟糕。

查看。你有任何基准测试结果吗?

As per my understanding BIrConverter is the apt option to convert byte
array to numeric. It has a property to check the endianness also -
IsLittleEndian. Do not know how bad it is from perdormance point of
view. Do you have any benchmark results?


Aneesh Pulukkul [ http://dotnet-revolutions.blogspot.com] 写道:
Aneesh Pulukkul [http://dotnet-revolutions.blogspot.com] wrote:

5月4日上午8:23,Arne Vajh? j< a ... @ vajhoej.dkwrote:
On May 4, 8:23 am, Arne Vajh?j <a...@vajhoej.dkwrote:

> Roy写道:
>Roy wrote:

> ;>将字节[]复制到诸如
之类的值的最佳性能是什么?
我使用的是BitConverter.ToInt64(二进制,偏移)
但是表现还不够好。在我的情况下,我需要有最好的表现。
>>What is the way to have best performance to copy a byte[] to a value such as
long?
I use
BitConverter.ToInt64(binary, offset)
But the performace is not good enough. I need to have the best performance
in my case.


与微软编码的一般情况相比,你是否知道你将拥有的字节使得它们特别好?

如果没有我发现很难相信能够找到更快的东西。

哦 - 你确定这真的是你应用程序的瓶颈吗?

(你应该能够每秒进行1到2亿转换)

Do you know something about the bytes you will have that makes them
special compared to the general case Microsoft has coded for ?

If not I find it difficult to believe that it will be possible
to find something faster.

Oh - and are you sure this is really the bottleneck in your app ??

(you should be able to do 100-200 million conversions per second)



根据我的理解,BIrConverter是转换字节的简单选项

数组到数字。它有一个属性来检查字节顺序 -

IsLittleEndian。不知道从perdormance点来看有多糟糕。

查看。你有任何基准测试结果吗?


As per my understanding BIrConverter is the apt option to convert byte
array to numeric. It has a property to check the endianness also -
IsLittleEndian. Do not know how bad it is from perdormance point of
view. Do you have any benchmark results?



endianess check是一个if语句(我用反射器查看)。


它使用shift和or创建很长的。


我不能马上想出任何我希望的建议

更快。


我对一个联合测试BitConverter(带字段偏移的结构)和

BitConverter要快得多。


如果它是一个巨大的数组需要转换,然后可能

a调用本机代码值得考虑。


Arne

The endianess check is a single if statement (I looked with reflector).

It uses shift and or to create the long.

I can not right away come up with any ideas that I would expect
to be faster.

I did test BitConverter against a union (struct with field offset) and
BitConverter was much faster.

If it was a huge array that needed to be converted, then possible
a call to native code could be worth considering.

Arne


这篇关于将byte []转换为值的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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