473,218 Members | 1,470 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,218 software developers and data experts.

char vs int speed

hello~!

I'm coding a simple program which demands fast speed.
and my cpu is 32bits.
which one is faster in processing array and loop? char? int?
Nov 29 '07 #1
10 6109
On Nov 29, 2:50 pm, dondora <koni...@hanmail.netwrote:
hello~!

I'm coding a simple program which demands fast speed.
and my cpu is 32bits.
which one is faster in processing array and loop? char? int?
Check the below link -
http://groups.google.co.id/group/com...ce7f9?lnk=raot

Karthik Balaguru
Nov 29 '07 #2
dondora wrote:
hello~!

I'm coding a simple program which demands fast speed.
and my cpu is 32bits.
which one is faster in processing array and loop? char? int?
This is the wrong group for such questions. Code performance is
intimately tied to compiler specific optimisations, hardware
capabilities and many other details. The C Standard says nothing about
the performance of C code.

<OT>
On a 32 bit system, it is very likely single operations on int are more
faster than on char. However for a very large array of such objects,
the memory saved by using char could very easily outweigh the fact that
native instructions on int are faster. All that the C Standard says is
that the type int is most likely to correspond to the native "word
size" of the underlying processor, hence it is most likely that (given
that other factors are equal), operations on it are faster than on a
char.

The only truly conclusive method to evaluate performance is to actually
test the code.
</OT>

Nov 29 '07 #3
dondora wrote:
I'm coding a simple program which demands fast speed.
and my cpu is 32bits.
which one is faster in processing array and loop? char? int?
It Depends.

If it's important to you, measure it. Remember that the results will
depend on your implementation and won't necessarily scale linearly
with the size of your input.

Standard C makes no promises about performance. If you tell us what
you're trying to do, we might be able to spot obvious gotchas or
suggest useful measurements.

--
Chris "everything is context, even when it isn't" Dollin

Hewlett-Packard Limited registered office: Cain Road, Bracknell,
registered no: 690597 England Berks RG12 1HN

Nov 29 '07 #4
On Nov 29, 9:50 am, dondora <koni...@hanmail.netwrote:
hello~!

I'm coding a simple program which demands fast speed.
and my cpu is 32bits.
which one is faster in processing array and loop? char? int?
Go to www.intel.com and download their processor manuals, then read
through them. They are free. Or go to www.amd.com and download their
manuals. They will even send them to you on a CD, for free. Then have
a look at www.ibm.com so you can get a set of PowerPC manuals. This
should give you some understanding of the matter, and some idea why
there is no one answer.

Alternative answer: Try both and measure the difference in speed. If
you can't measure a difference, then it doesn't matter. If you can
measure a difference, take the faster.
Nov 29 '07 #5
In article <5a**********************************@o6g2000hsd.g ooglegroups.com>,
christian.bau <ch***********@cbau.wanadoo.co.ukwrote:
>On Nov 29, 9:50 am, dondora <koni...@hanmail.netwrote:
>I'm coding a simple program which demands fast speed.
and my cpu is 32bits.
which one is faster in processing array and loop? char? int?
>Alternative answer: Try both and measure the difference in speed. If
you can't measure a difference, then it doesn't matter. If you can
measure a difference, take the faster.
Though be sure to measure in a truly representative code sample.
For example, your program, coded using char, might happen to have
all of the most-needed data fit into the CPU data cache, but the
same program coded using int might happen to not fit the same data
completely into the CPU data cache. For some data access patterns
the difference would be quite noticable; for other data access
patterns, the difference would be minor. (And if you are working
at this level, then "cache-line aliasing" can make a huge difference.)

--
"Any sufficiently advanced bug is indistinguishable from a feature."
-- Rich Kulawiec
Nov 29 '07 #6
dondora:
hello~!

I'm coding a simple program which demands fast speed. and my cpu is
32bits.
which one is faster in processing array and loop? char? int?

Only resort to theory if there's no practical means of experiment.

#include <stdio.h>

typedef unsigned Type;
#define SPECIF "%u"

int main(void)
{
unsigned i;

Type obj;

scanf(SPECIF,&obj);

/* Print the time */

for(i = 0; i != 65000u; ++i) obj *= obj;

/* Print the time again */

return 0;
}

Then try it with an unsigned char.
A rule of thumb though...

If you're dealing with a CPU which is 16-Bit or greater, than int is
likely to be faster than char. Otherwise, char is likely to be faster
than int.

You might be wise to go with types such as "int_fastest_atleast_8" (I
don't know if that's its exact name).

--
Tomás Ó hÉilidhe
Nov 29 '07 #7
Toms hilidhe wrote:
...
You might be wise to go with types such as "int_fastest_atleast_8" (I
don't know if that's its exact name).
There's an int_fast8_t which is the fastest type with at least 8 bits,
and there's int_least8_t, which is the smallest type with at least 8
bits.
Nov 29 '07 #8
Toms hilidhe <to*@lavabit.comwrites:
dondora:
>I'm coding a simple program which demands fast speed. and my cpu is
32bits.
which one is faster in processing array and loop? char? int?

Only resort to theory if there's no practical means of experiment.
For benchmarking, that often makes sense. But I hope that you
don't apply this as a general principle to everything in C,
because the C language has many areas of undefined and
implementation-defined behavior. If you depend on the results of
experiments, then you can unwittingly stray into one of these
area and make your software unnecessarily unportable.
--
Ben Pfaff
http://benpfaff.org
Nov 29 '07 #9
ja*********@verizon.net writes:
Tomás Ó hÉilidhe wrote:
...
>You might be wise to go with types such as "int_fastest_atleast_8" (I
don't know if that's its exact name).

There's an int_fast8_t which is the fastest type with at least 8 bits,
and there's int_least8_t, which is the smallest type with at least 8
bits.
Both of which are defined in <stdint.h>, which is a new header in C99.
Not all implementations provide it.

int_least8_t is pretty much guaranteed to be signed char, or perhaps
plain char if plain char is signed. (It *might* be something else in
an implementation that provides extended integer types, but there's no
point in making it anything other than signed char or char.)

int_fast8_t will probably be either the same as int_least8_t, or
signed int. (I'm a little surprised to find that int_fast8_t is 8
bits under gcc on an x86 system.) But if you want fast computations
and you don't have <stdint.h>, int is likely to be your best bet.

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Nov 29 '07 #10
On Thu, 29 Nov 2007 01:50:01 -0800 (PST), dondora
<ko*****@hanmail.netwrote in comp.lang.c:
hello~!

I'm coding a simple program which demands fast speed.
How does it demand fast speed? In wring, on the phone, in an email?
What is your definition of "fast speed"?
and my cpu is 32bits.
which one is faster in processing array and loop? char? int?
Each is faster than the other.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Nov 30 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Kamilche | last post by:
I was looking for a way to speed up detecting invalid characters in my TCP string, and thought of yet another use for the translate function! If you were to 'translate out' the bad characters, and...
4
by: Joseph Suprenant | last post by:
I have an array of unsigned chars and i would like them converted to an array of ints. What is the best way to do this? Using RedHat 7.3 on an Intel Pentium 4 machine. Having trouble here, hope...
2
by: Miss Livvy | last post by:
Would it be OK to use varchar(5) instead of char(5) as the first field of a composite clustered index? My gut tells me that varchar would be a bad idea, but I am not finding much information on...
10
by: Ramprasad A Padmanabhan | last post by:
Hello all, On my linux box ( redhat 7.2 ), I have been using char as a boolean data type. In order to save on the number of bytes as compared to using int or short int. typedef char boolean;...
4
by: Mark | last post by:
Is there a way to convert a char to a DateTime without first converting to a string and using DateTime.Parse or ParseExact? I'm trying to reuse the char which can be reused instead of converting...
18
by: Daz | last post by:
Hi all! I know this sounds like a stupid question, but I need to varify whether ot not a single char (from a char array) is a number. I have tried using atoi, but it seems to return '0' for any...
74
by: aruna.mysore | last post by:
Hi all, I have a simple definitioin in a C file something like this. main() { char a; ....... int k; }
21
by: Hallvard B Furuseth | last post by:
Is the code below valid? Generally a value must be accessed through the same type it was stored as, but there is an exception for data stored through a character type. I'm not sure if that...
12
by: karthikbalaguru | last post by:
Hi, How is 'Int' Faster than 'Char' ? I think , 'Char' is small and so it should be easily & efficiently . Can someone here provide some info regarding this. Thanks and Regards, Karthik...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.