Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 63f316f1 authored by Tim Murray's avatar Tim Murray Committed by Android (Google) Code Review
Browse files

Merge "Java RS latency benchmark."

parents 085c47c7 3ffedae9
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
#
# Copyright (C) 2012 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := tests

LOCAL_SRC_FILES := $(call all-java-files-under, src) \
                   $(call all-renderscript-files-under, src)

LOCAL_PACKAGE_NAME := RsLatencyBenchmark

include $(BUILD_PACKAGE)
+30 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2012 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.rs.latencybench">

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-sdk android:minSdkVersion="17" />
    <application android:label="_RS_Latency_Bench">
        <activity android:name="LatencyBench">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>
+31 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2012 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <ImageView
        android:id="@+id/displayin"
        android:layout_width="320dip"
        android:layout_height="266dip" />

    <ImageView
        android:id="@+id/displayout"
        android:layout_width="320dip"
        android:layout_height="266dip" />

</LinearLayout>
+63 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.example.android.rs.latencybench;
import android.content.Context;
import android.content.res.Resources;
import android.renderscript.*;

public class Benchmark implements Runnable {
    private final RenderScript mRS;
    private ScriptC_compute_benchmark mScript;
    private Allocation ain;
    private Allocation aout;

    public Benchmark(RenderScript rs, Resources res) {
        mRS = rs;
        mScript = new ScriptC_compute_benchmark(mRS, res, R.raw.compute_benchmark);
        ain = Allocation.createSized(rs, Element.U32(mRS), 10000);
        aout = Allocation.createSized(rs, Element.U32(mRS), 10000);
    }

    public void run() {
        int[] temp;
        temp = new int[1];

        long t = java.lang.System.currentTimeMillis();

        for (int i = 0; i < 1000000; i++)
            mScript.forEach_root(ain, aout);
        aout.copy1DRangeFrom(0, 1, temp);

        t = java.lang.System.currentTimeMillis() - t;
        android.util.Log.v("LatencyBench", "Iterated Java forEach took " + t + " ms");

        mScript.set_empty_kern(mScript);
        mScript.set_in(ain);
        mScript.set_out(aout);

        t = java.lang.System.currentTimeMillis();
        mScript.invoke_emptyKernelLauncher();
        aout.copy1DRangeFrom(0, 1, temp);

        t = java.lang.System.currentTimeMillis() - t;
        android.util.Log.v("LatencyBench", "Invoked forEach took " + t + " ms");



    }

}
+37 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.example.android.rs.latencybench;

import android.app.Activity;
import android.os.Bundle;
import android.renderscript.RenderScript;

public class LatencyBench extends Activity {
    private RenderScript mRS;
    private Benchmark mBenchmark;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mRS = RenderScript.create(this);

        mBenchmark = new Benchmark(mRS, getResources());
        mBenchmark.run();
    }
}
Loading