1/* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.example.android.rs.latencybench; 18import android.content.Context; 19import android.content.res.Resources; 20import android.renderscript.*; 21 22public class Benchmark implements Runnable { 23 private final RenderScript mRS; 24 private ScriptC_compute_benchmark mScript; 25 private Allocation ain; 26 private Allocation aout; 27 28 public Benchmark(RenderScript rs, Resources res) { 29 mRS = rs; 30 mScript = new ScriptC_compute_benchmark(mRS); 31 ain = Allocation.createSized(rs, Element.U32(mRS), 10000); 32 aout = Allocation.createSized(rs, Element.U32(mRS), 10000); 33 } 34 35 public void run() { 36 int[] temp; 37 temp = new int[1]; 38 39 long t = java.lang.System.currentTimeMillis(); 40 41 for (int i = 0; i < 1000000; i++) 42 mScript.forEach_root(ain, aout); 43 aout.copy1DRangeFrom(0, 1, temp); 44 45 t = java.lang.System.currentTimeMillis() - t; 46 android.util.Log.v("LatencyBench", "Iterated Java forEach took " + t + " ms"); 47 48 mScript.set_empty_kern(mScript); 49 mScript.set_in(ain); 50 mScript.set_out(aout); 51 52 t = java.lang.System.currentTimeMillis(); 53 mScript.invoke_emptyKernelLauncher(); 54 aout.copy1DRangeFrom(0, 1, temp); 55 56 t = java.lang.System.currentTimeMillis() - t; 57 android.util.Log.v("LatencyBench", "Invoked forEach took " + t + " ms"); 58 59 60 61 } 62 63} 64