import edu.rice.cs.mint.runtime.Code;
import edu.rice.cs.mint.runtime.SafeCode;
import edu.rice.cs.mint.util.Benchmark;

public class Power_ForBench {
    public static int power(int x, int n){
	int acc = 1;
	for(int i=0;i<n;++i) acc = acc * x;
	return acc;
    }
    
    public static separable
	SafeCode<Integer> spower(SafeCode<Integer> x, int n){
	SafeCode<Integer> acc = <| 1 |>;
	for(int i=0;i<n;++i) acc = <| `acc * `x |>;
	return acc;
    }
    
    public void run() {
        System.out.println("power(2,17)");
        Benchmark.TimedTask[] results =
            Benchmark.benchmark(Benchmark.stagingTasks(new Benchmark.Task() {
            public void run() {
                //
                // call unstaged code here
                //
                power(2, 17);
                //
                //
                //
            }
        }, new Benchmark.Thunk<Code<? extends Benchmark.Task>>() {
            public Code<? extends Benchmark.Task> value() {
                return <| new Benchmark.Task() {
                    public void run() {
                        //
                        // splice in staged code here
                        //
                        int i = `(spower(<| 2 |>, 17));
                        //
                        //
                        //
                    }
                } |>;
            }
        }));
        
//        Benchmark.print(0, results); // relative to unstaged
//        System.out.println();
        Benchmark.print(results.length-1, results); // relative to staged
    }
    
    public static void main(String[] args) {
        new Power4().run();
    }
}

