Re: Unsigned integers



Bob Butler wrote:
> "Danny" <NOSPAMFORdaniel_ahorn@xxxxxxxxx> wrote in message
> news:ru0k81dcot63qlc4kk02gsvql6aksu5h38@xxxxxxx
>> Date: Mon, 16 May 2005 07:54:27 -0700
>> Name: "Bob Butler" <tiredofit@xxxxxxxxxx>
>>
>>> "Danny" <NOSPAMFORdaniel_ahorn@xxxxxxxxx> wrote in message
>>> news:52ch8194jqga5pml24b4bkteikh71benpq@xxxxxxx
>>>> Which is exactly why I didn't say "best" but "most efficient". ;o)
>>>>
>>>> You know, in terms of storage one that requires least amount of
>>>> memory, in terms of speed one that runs the fastest. The two
>>>> usually go together.
>>>
>>> IME the two are more likely to be mutually exclusive
>>
>> Not in this case because we're talking about data. The less data
>> there is, the more efficient it will be.
>
> I'm not sure I understand what you are trying to say. Tightly packed
> data can require extra processing steps to read/write making the
> process slower than it would be if the data were in a more easily
> accessible format. In that respect compactness of storage format and
> speed of processing are very often tradeoffs.
>
>> It is mutually exclusive in case of code, however. There, indeed, the
>> choice is usually between size and speed. For example, tight code is
>> less efficient (albeit more elegant, of course) than "unrolled loops'
>> which by comparison run faster.
>
> I have absolutely no idea what you are trying to say there. "tight
> code" is quite often more efficient (assuming speed=efficiency) and
> elegance is in the eye of the beholder. highly optimized code is
> often a nightmare to maintain and that makes it inelegant IMO. I've
> never heard the term "unrolled loop" and have no clue what you mean
> by that.

Loop unrolling is a common optimization in ASM, where instead of executing one operation on each iteration of a counter, you execute (say) 8 or 16. This reduces the number of jumps, which are usually costly, at the expense of code space. There's another tradeoff point where your unrolled code size exceeds the size of a cache line, so total unrolling is not often as efficient as partial unrolling.

It's generally true at the machine code level that small code = fast code, but there are enough exceptions that such a claim will rarely go unchallenged. In order to know, you must test and time.

And I'm with you that small data doesn't always, or even usually, mean fast code. Using a short int to save space is going to cost you some speed when the native word size is a long int.

The _reductio_ case is using bits to store binary values -- yes, you'll save space if you keep 1024 booleans in 32 dwords, but at a great cost in access time.

--
Jim

.



Relevant Pages

  • Re: Batch sent X10 command
    ... another possible approach for a 5 second delay: ... A far more elegant approach for a delay is to use the "sleep" command ... It may be "elegant" but it doesn't actually work within the scope of what ... INT 21 ...
    (comp.home.automation)
  • Re: Passing an array of struct to function
    ... arnuld said: ... I am getting Segfaults and weired values. ... is there any elegant way ... int main ...
    (comp.lang.c)
  • Re: Problem with input streams
    ... > int main ... Are there flags that I have to change or something to reset fin? ... I'm no guru on streams so won't give you an elegant answer. ... solve your second problem. ...
    (comp.lang.cpp)
  • Re: How to create large files with c?
    ... My manager told me to create a large file of 2GB ... and the secod 1GB is filled with "World" ... Sorry to say that I don't know how to do that in an elegant way. ... int main ...
    (comp.lang.c)