PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.c > char vs int speed
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
char vs int speed

Réponse
 
LinkBack Outils de la discussion
Vieux 29/11/2007, 09h50   #1
dondora
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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?
  Réponse avec citation
Vieux 29/11/2007, 09h53   #2
karthikbalaguru
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: char vs int speed

On Nov 29, 2:50 pm, dondora <koni...@hanmail.net> 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?


Check the below link -
http://groups.google.co.id/group/com...ce7f9?lnk=raot

Karthik Balaguru
  Réponse avec citation
Vieux 29/11/2007, 10h11   #3
santosh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: char vs int speed

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>

  Réponse avec citation
Vieux 29/11/2007, 10h29   #4
Chris Dollin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: char vs int speed

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

  Réponse avec citation
Vieux 29/11/2007, 16h51   #5
christian.bau
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: char vs int speed

On Nov 29, 9:50 am, dondora <koni...@hanmail.net> 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?


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.
  Réponse avec citation
Vieux 29/11/2007, 17h15   #6
Walter Roberson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: char vs int speed

In article <5aa81a57-0712-4d23-841e-21618197ef28@o6g2000hsd.googlegroups.com>,
christian.bau <christian.bau@cbau.wanadoo.co.uk> wrote:
>On Nov 29, 9:50 am, dondora <koni...@hanmail.net> 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?


>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
  Réponse avec citation
Vieux 29/11/2007, 17h57   #7
Tomás Ó hÉilidhe
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: char vs int speed

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
  Réponse avec citation
Vieux 29/11/2007, 18h03   #8
jameskuyper@verizon.net
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: char vs int speed

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.
  Réponse avec citation
Vieux 29/11/2007, 19h34   #9
Ben Pfaff
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: char vs int speed

Tomás Ó hÉilidhe <toe@lavabit.com> writes:

> 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
  Réponse avec citation
Vieux 29/11/2007, 19h47   #10
Keith Thompson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: char vs int speed

jameskuyper@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) <kst-u@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"
  Réponse avec citation
Vieux 30/11/2007, 03h16   #11
Jack Klein
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: char vs int speed

On Thu, 29 Nov 2007 01:50:01 -0800 (PST), dondora
<koninja@hanmail.net> wrote 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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 11h33.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,24914 seconds with 19 queries