Which is faster?

Which is faster?

Post by Kurtis D. Rade » Sun, 11 Aug 2002 13:58:32




> There are three methods that produce same result value.

> Case of 1
> char a = 18, b = 17, result;
> a = a >> 4; b = b >> 4;
> result = a - b;

> Case of 2
> char a = 18, b = 17, result;
> a = a & 0xF0;
> b = b & 0xF0;
> result = a - b;

> Case of 3
> char a = 18, b = 17, result;
> a = a - 15;
> b = b - 15;
> result = a - b;

Those three fragments do not produce the same value if compiled by an ANSI
standards compliant C compiler. Did you actually compile and run your
examples? If so, and they produced the same output, I would suggest using a
different system. Place the following in a file, compile it, and run it:

#include <stdio.h>
int main() {
    char a, b, result;

    a = 18, b = 17;
    a = a >> 4; b = b >> 4;
    result = a - b;
    printf( "%d\n", result );

    a = 18, b = 17;
    a = a & 0xF0;
    b = b & 0xF0;
    result = a - b;
    printf( "%d\n", result );

    a = 18, b = 17;
    a = a - 15;
    b = b - 15;
    result = a - b;
    printf( "%d\n", result );

Quote:}

You should get three lines of output:

    0
    0
    1

Quote:> Can anyone tell me which is faster and effective? And what's the reason?

Even assuming all three variants produced the same result the answer to your
question is: It depends. It depends on your CPU architecture. It depends on
your compiler. It depends on the compilation options you use.
 
 
 

1. Faster client or faster server??

We're an academic institution with a server which is a SPARCstation 2 and ten
clients which are a collection of SPARC IPC's and ELC's.  We're on an Ethernet
network (10base2) and just upgraded from SunOS 4.1.3 to Solaris 2.4.

The traffic on the network is mainly running applications and data, all of
which is stored on the server.  The clients each have the system installed
locally, with all man pages, data, programs (other than system), etc. on disks
served by our server.  Our server has a PrestoServe board, and two SCSI chains,
with a total of 8 gigabytes of space on the drives (four 1.3's and a 4 gig).

We also have just purchased a SPARCstation 4 -- I'm not sure what would be
involved in getting the PrestoServe board into that (or even if we could), and
I don't believe it has two SCSI chains.

The question is, will we see a speed gain if we change our server from the
SPARCstation 2 to the SPARCstation 4, or is this rather pointless because our
clients are slow as well?  The SPARC 4 is either going to be a server, which
would (ideally) speed up the system, or it will be a client, where its higher
quality display and faster local disk will be better for whomever is using it
at the time (or it may go in a professor's office, that has not been decided).

Melissa Binde
Swarthmore College
Student System Administrator

2. question about dbx and fork(2)

3. seti@home faster and faster, etc.

4. Conflict between v4l and adi module

5. This clone thing...am I stupid, or am I right?

6. Ethernet bonding????

7. 'Split kernel' linux on Sun's new Workstation

8. I am with the following error, when i am running lilo...

9. Am I touchy? Or am I right?

10. Am I seeing IPv5, or am I hallucinating?

11. I am buying an Ultra 5 but am lost in part numbers ....

12. I am in text mode, what browser am I running....