GVSU CIS 343

The Main Tradeoff

for (int i = 0; i < size; ++i) {
  c[i] = a[i] + b[i];
}

vs.

for (int i = 0; i < size; i+= 2) {
  c[i] = a[i] + b[i];
  c[i+1] = a[i+1] + b[i+1]
}

vs.

int* end = c + size*sizeof(int)
while (c < end) {
  *c = *a + *b;
  ++a; ++b; ++c;
  *c = *a + *b;
  ++a; ++b; ++c;
    *c = *a + *b;
  ++a; ++b; ++c;
  *c = *a + *b;
  ++a; ++b; ++c;
    *c = *a + *b;
  ++a; ++b; ++c;
  *c = *a + *b;
  ++a; ++b; ++c;
}

Top code is easiest to read; but bottom code is faster. Over time compilers have improved to provide for “bottom” performance using “top” code.

Other key features / tradeoffs

(In other words, what makes a language “good”?)

use v5.10;

while (<STDIN>) {
    chomp;
    say if (/z/)
}

vs.

use v5.10;
 
while ($_ = <STDIN>) {
   chomp $_;
   if ($_ =~ /MATCH/) {
      say $_;
   }
}

Static vs. Dynamic typing

Compile vs. Interpret