"Faster than C?" I think you'll find that these are just compiler optimisations, not that the code is actually faster.
For example, from (pseudo) Spec#:
ensures result > 0
ensures (p == q) implies result = 0
public int Distance(Point! p, Point! q){
return (int)Math.Sqrt( (p.x - q.x) * (p.x - q.x) + (p.y - q.y) * (p.y - q.y) );
}
requires p > 0
ensures p == 0
public int factorial(int p){
if(p == 0) return 1;
return p * factorial(p - 1);
}
public static void main(){
int i = 7;
// Spec# should be able to avoid the if( !(p > 0) ) throw new ArgumentException("p > 0 assertion failed"); step here
// because it knows the parameter here. In C this would typically happen inside the function.
Console.WriteLine( factorial( i ) );
// Spec# can probably optimise away this entire function, since distance contains no side-effects and the first ensures
// defines the result of the function.
Console.WriteLine( distance(new Point(i, i), new Point(i, i) ));
}
Note that while this is "better than C performance", it's not better than an ideal C representation of the program:
int factorial(int f){
if(f == 0) return 1;
return factorial(f - 1) * f;
}
void main(){
printf("%d\n0", factorial(i));
}
But is better than a non-ideal version of the program:
int factorial(int f){
assert(f < 0);
if(f == 0) return 1;
return f * factorial(f - 1);
}
int distance(struct Point* p, struct Point* q){
assert(p != NULL);
assert(q != NULL);
return (int)sqrt( (p->x - q->x) * (p->x - q->x) + (p->y - q->y) * (p->y - q->y) );
}
void main(){
int i = 7;
struct Point* a, b;
printf("%d\n", factorial(i));
a = malloc(sizeof(Point));
b = malloc(sizeof(Point));
a->x = i;
a->y = i;
b->x = i;
b->y = i;
printf("%d\n", distance(a, b));
free(a);
free(b);
}
Because C is so close to assembly language, it's fairly simple to deconstruct assembly language into C. Consequently any high-level language that runs "faster than C" is usually lying, because the high level language can be decomposed to assembler and recomposed to C, which by-defintion runs in the same speed. High level languages have lots of benefits, but when there are additional constraints such as garbage collection, C will nearly always win in a straight battle of which has the higher theoretical speed for an algorithm.