blob: cbf145c7ee2e126b1115e13da5f66fa51b290977 [file] [log] [blame]
Keun young Park4403e502012-09-19 18:11:07 -07001/*
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
17#include <jni.h>
18#include <stdlib.h>
19#include <string.h>
20#include <sys/time.h>
21
Keun young Park1665af12012-12-17 10:57:09 -080022double currentTimeMillis()
Keun young Park4403e502012-09-19 18:11:07 -070023{
24 struct timeval tv;
25 gettimeofday(&tv, (struct timezone *) NULL);
Keun young Park1665af12012-12-17 10:57:09 -080026 return tv.tv_sec * 1000.0 + tv.tv_usec / 1000.0;
Keun young Park4403e502012-09-19 18:11:07 -070027}
28
Stuart Scott5d509992015-09-15 10:56:10 -070029extern "C" JNIEXPORT jdouble JNICALL Java_android_dram_cts_MemoryNative_runMemcpy(JNIEnv* env,
Keun young Park697f5642012-11-01 10:34:23 -070030 jclass clazz, jint bufferSize, jint repetition)
Keun young Park4403e502012-09-19 18:11:07 -070031{
Keun young Park697f5642012-11-01 10:34:23 -070032 char* src = new char[bufferSize];
33 char* dst = new char[bufferSize];
Keun young Park4403e502012-09-19 18:11:07 -070034 if ((src == NULL) || (dst == NULL)) {
Keun young Park697f5642012-11-01 10:34:23 -070035 delete[] src;
36 delete[] dst;
Keun young Park4403e502012-09-19 18:11:07 -070037 env->ThrowNew(env->FindClass("java/lang/OutOfMemoryError"), "No memory");
Keun young Park697f5642012-11-01 10:34:23 -070038 return -1;
Keun young Park4403e502012-09-19 18:11:07 -070039 }
40 memset(src, 0, bufferSize);
41 memset(dst, 0, bufferSize);
Keun young Park1665af12012-12-17 10:57:09 -080042 double start = currentTimeMillis();
Keun young Park4403e502012-09-19 18:11:07 -070043 for (int i = 0; i < repetition; i++) {
44 memcpy(dst, src, bufferSize);
45 src[bufferSize - 1] = i & 0xff;
46 }
Keun young Park1665af12012-12-17 10:57:09 -080047 double end = currentTimeMillis();
Keun young Park697f5642012-11-01 10:34:23 -070048 delete[] src;
49 delete[] dst;
Keun young Park4403e502012-09-19 18:11:07 -070050 return end - start;
51}
Keun young Park50418e92012-12-17 11:34:45 -080052
Stuart Scott5d509992015-09-15 10:56:10 -070053extern "C" JNIEXPORT jdouble JNICALL Java_android_dram_cts_MemoryNative_runMemset(JNIEnv* env,
Keun young Park50418e92012-12-17 11:34:45 -080054 jclass clazz, jint bufferSize, jint repetition, jint c)
55{
56 char* dst = new char[bufferSize];
57 if (dst == NULL) {
58 delete[] dst;
59 env->ThrowNew(env->FindClass("java/lang/OutOfMemoryError"), "No memory");
60 return -1;
61 }
62 memset(dst, 0, bufferSize);
63 double start = currentTimeMillis();
64 for (int i = 0; i < repetition; i++) {
65 memset(dst, (c + i) & 0xff, bufferSize);
66 }
67 double end = currentTimeMillis();
68 delete[] dst;
69 return end - start;
70}
71