xref: /aosp_15_r20/frameworks/rs/tests/java_api/ComputePerf/src/com/example/android/rs/computeperf/ComputePerf.java (revision e1eccf28f96817838ad6867f7f39d2351ec11f56)
1 /*
2  * Copyright (C) 2011-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 
17 package com.example.android.rs.computeperf;
18 
19 import android.app.Activity;
20 import android.os.Bundle;
21 import android.graphics.BitmapFactory;
22 import android.graphics.Bitmap;
23 import android.renderscript.RenderScript;
24 import android.renderscript.Allocation;
25 import android.util.Log;
26 import android.widget.ImageView;
27 
28 public class ComputePerf extends Activity {
29     private LaunchTest mLT;
30     private Mandelbrot mMandel;
31     private RenderScript mRS;
32 
33     @Override
onCreate(Bundle savedInstanceState)34     protected void onCreate(Bundle savedInstanceState) {
35         super.onCreate(savedInstanceState);
36         setContentView(R.layout.main);
37 
38         final int numTries = 100;
39 
40         long timesXLW = 0;
41         long timesXYW = 0;
42 
43         mRS = RenderScript.create(this);
44         mLT = new LaunchTest(mRS, getResources());
45         mLT.XLW();
46         mLT.XYW();
47         for (int i = 0; i < numTries; i++) {
48             timesXLW += mLT.XLW();
49             timesXYW += mLT.XYW();
50         }
51 
52         timesXLW /= numTries;
53         timesXYW /= numTries;
54 
55         // XLW and XYW running times should match pretty closely
56         Log.v("ComputePerf", "xlw launch test " + timesXLW + "ms");
57         Log.v("ComputePerf", "xyw launch test " + timesXYW + "ms");
58 
59         mMandel = new Mandelbrot(mRS, getResources());
60         mMandel.run();
61     }
62 }
63