Raffaele Gravina escribió:
> Hi all,
> 
> I'd like to bring to your attention the following two equivalent snippet 
> of code:
> 
> ***************   A  ********************
> event void Read.readDone(error_t result, val_t val) {
>                 
>         curr = val;
>                 
>         if (haveHistory && (pre - curr) > 0)) {
>             // do something
>         }
> 
>         pre = curr;
> 
>        haveHistory = TRUE;
> }
> *****************************************
> 
> ***************   B  ********************
> event void Read.readDone(error_t result, val_t val) {
>                 
>         curr = val;
>                 
>         if (haveHistory && (pre - curr) > 0)) {
>             // do something
>         }
> 
>         pre = curr;
> 
>         if( ! haveHistory )
>             haveHistory = TRUE;
> }
> *****************************************
> 
> 
> Given that A and B are semantically the same and hence the "if ( 
> ! haveHistory )" in B could be removed with no effect to the correctness, 
> let's suppose the readDone event fires quite often; my question is:
> 
> Is A more time and energy efficient than B?
> 
> I'm pretty sure the "if ( ! haveHistory )" statement takes more CPU 
> cycles than the simple "haveHistory = TRUE" assignement, so A should be 
> definitely quicker than B;
> however, what about the energy consumed?!? 
> 

I don't know :-) these are my thoughts:

* Compilers had very good optimizers. It's possible both snippets 
compile to the same assembler code. If you want to do so fine 
calculations you have to compare generated asm code not original nesc code.

* In A you have a assignation only. In B, you have a comparison and a 
jump (in false case) or a comparison and assignation (in true case). 
What are the probability of every case?



_______________________________________________
Tinyos-help mailing list
Tinyos-help@millennium.berkeley.edu
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to