原始类型的时间与空间权衡 [英] time vs. space tradeoffs of primitive types
问题描述
据我所知,由于字边界,不同的整数类型可能会有时间损失
。我在哪里可以获得澄清的信息
这个主题?一个快速的谷歌对我来说并没有多少...很好的小
C ++与维基百科上的Java巨魔之战但我没有看到什么
对于。我想知道是否使用较小类型节省空间来代表
代表您知道的数量很少的数字。我还想
想知道使用这些较小的类型与
相关的性能惩罚。
I understand that different integer types might have time penalties
because of word boundaries. Where can I get information clarifying
this topic? A quick google didn''t turn up much for me...nice little
C++ vs. Java troll war on wikipedia but nothing on what I''m looking
for. I want to know whether space savings using smaller types to
represent numbers you know will be small are ever seen. I would also
like to know what kind of performance penalties are associated with
using these smaller types.
推荐答案
Noah Roberts写道:
Noah Roberts wrote:
我明白不同的整数类型可能会有时间处罚
因为字边界。我在哪里可以获得澄清的信息
这个主题?一个快速的谷歌对我来说并没有多少...很好的小
C ++与维基百科上的Java巨魔之战但我没有看到什么
对于。我想知道是否使用较小类型节省空间来代表
代表您知道的数量很少的数字。我还想
想知道使用这些较小类型与
相关的性能惩罚。
I understand that different integer types might have time penalties
because of word boundaries. Where can I get information clarifying
this topic? A quick google didn''t turn up much for me...nice little
C++ vs. Java troll war on wikipedia but nothing on what I''m looking
for. I want to know whether space savings using smaller types to
represent numbers you know will be small are ever seen. I would also
like to know what kind of performance penalties are associated with
using these smaller types.
我认为这取决于架构......例如在32位
例子.. proccessor无论如何都将取一个32位的值
I think it depends on the architecture .. for example on a 32-bit
system there''s no speed/time penalty in using an int vs a short for
example .. the proccessor will fetch a 32-bit value anyway
Noah Roberts写道:
Noah Roberts wrote:
我明白不同的整数类型可能因为字边界而有时间惩罚
。我在哪里可以获得澄清的信息
这个主题?一个快速的谷歌对我来说并没有多少...很好的小
C ++与维基百科上的Java巨魔之战但我没有看到什么
对于。我想知道是否使用较小类型节省空间来代表
代表您知道的数量很少的数字。我还想
想知道使用这些较小类型与
相关的性能惩罚。
I understand that different integer types might have time penalties
because of word boundaries. Where can I get information clarifying
this topic? A quick google didn''t turn up much for me...nice little
C++ vs. Java troll war on wikipedia but nothing on what I''m looking
for. I want to know whether space savings using smaller types to
represent numbers you know will be small are ever seen. I would also
like to know what kind of performance penalties are associated with
using these smaller types.
性能处罚取决于上下文和平台。一个
原始类型有一个范围,一个最小值和最大值以及一些有趣的常量。您可以使用< limitsheader来剖析
原语的各种质量。请注意,如果您选择的
原语生成溢出,则性能= 0。因此,在您开始关注
之前,请考虑其后果。
#include< limits>
模板< typename T>
void Numerics(const T& r_t)
{
std :: cout<< " \ antype:" << typeid(r_t).name();
bool is_int = std :: numeric_limits< T> :: is_integer;
std :: cout<< " \ ninteger =" << is_int;
bool is_signed = std :: numeric_limits< T> :: is_signed;
std :: cout<< " \ bitsigned =" << is_signed;
std :: cout<< " \tsizeof =" << sizeof(r_t);
T min = std :: numeric_limits< T> :: min();
std :: cout<< \ nmin =" << min;
T max = std :: numeric_limits< T> :: max();
std :: cout<< \ nmax =" << max;
long capacity = static_cast< long>(max) - min;
std :: cout<< \ ncapacity =" <<容量;
std :: cout<< std :: endl;
}
int main()
{
int n( 0);
数字(n);
//等
}
Performance penalties depends on the context and the platform. A
primitive type has a range, a min and max value as well as a few more
interesting constants. You can dissect the various qualities of a
primitive using the <limitsheader. Note that performance = 0 if the
primitive you choose generates an overflow. So before you get concerned
with speed, consider the ramifications.
#include <limits>
template< typename T >
void Numerics( const T& r_t )
{
std::cout << "\ntype: " << typeid(r_t).name();
bool is_int = std::numeric_limits< T >::is_integer;
std::cout << "\ninteger = " << is_int;
bool is_signed = std::numeric_limits< T >::is_signed;
std::cout << "\tsigned = " << is_signed;
std::cout << "\tsizeof = " << sizeof(r_t);
T min = std::numeric_limits< T >::min();
std::cout << "\nmin = " << min;
T max = std::numeric_limits< T >::max();
std::cout << "\nmax = " << max;
long capacity = static_cast<long>(max) - min;
std::cout << "\ncapacity = " << capacity;
std::cout << std::endl;
}
int main()
{
int n(0);
Numerics(n);
// etc
}
st *********** **** @gmail.com 写道:
Noah Roberts写道:
Noah Roberts wrote:
据我所知,由于字边界,不同的整数类型可能会有时间损失
。我在哪里可以获得澄清的信息
这个主题?一个快速的谷歌对我来说并没有多少...很好的小
C ++与维基百科上的Java巨魔之战但我没有看到什么
对于。我想知道是否使用较小类型节省空间来代表
代表您知道的数量很少的数字。我还想
想知道使用这些较小类型与
相关的性能惩罚。
I understand that different integer types might have time penalties
because of word boundaries. Where can I get information clarifying
this topic? A quick google didn''t turn up much for me...nice little
C++ vs. Java troll war on wikipedia but nothing on what I''m looking
for. I want to know whether space savings using smaller types to
represent numbers you know will be small are ever seen. I would also
like to know what kind of performance penalties are associated with
using these smaller types.
我认为这取决于架构......例如在32位
示例.. proccessor将获取一个32位的值无论如何
I think it depends on the architecture .. for example on a 32-bit
system there''s no speed/time penalty in using an int vs a short for
example .. the proccessor will fetch a 32-bit value anyway
它不会必须做更多的处理步骤才能使用一半的
一旦它取出它的值?
It doesn''t have to do more processing steps to work with only half of
that value once it fetches it?
这篇关于原始类型的时间与空间权衡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!