1

I am programming C on linux, and which is faster in the following conditions?

1.processing 32bit integers on 32bit hardware and 64bit hardware

2.processing 64bit integers on 32bit hardware and 64bit hardware

Mickey Shine
  • 12,187
  • 25
  • 96
  • 148

1 Answers1

1

You should tell on what exact hardware, and what kind of processing.

And more importantly, you should benchmark your application, taking into account that premature optimization is evil.

Standard C99 provides you with the <stdint.h> with the fastint_t type (and others, e.G. intptr_t or int32_t...); there is also a <inttypes.h> standard header.

I believe you should not bother at first. If you know that some integer data type is very crucial to your application, you might use your own typedef, eg.

typedef intfast_t myimportantint_t;

Then you develop your application using appropriately myimportantint_t, and benchmark it. You can then easily change that typedef. (So changing the size of your important integers would be easy, just changing that typedef and perhaps defining a MYIMPORTANT_MAX preprocessor constant, etc.).

See this question very related to yours.

I believe you should not care that much.

Of course, 64 bits arithmetic on many 32 bits processors is more costly than 32 bits arithmetic.

Community
  • 1
  • 1
Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547