Home | History | Annotate | Download | only in os
      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 
     17 package android.os;
     18 
     19 import com.google.caliper.SimpleBenchmark;
     20 
     21 public class ParcelBenchmark extends SimpleBenchmark {
     22 
     23     private Parcel mParcel;
     24 
     25     @Override
     26     protected void setUp() {
     27         mParcel = Parcel.obtain();
     28     }
     29 
     30     @Override
     31     protected void tearDown() {
     32         mParcel.recycle();
     33         mParcel = null;
     34     }
     35 
     36     public void timeWriteByte(int reps) {
     37         final byte val = 0xF;
     38         for (int i = 0; i < reps; i++) {
     39             mParcel.writeByte(val);
     40         }
     41     }
     42 
     43     public void timeReadByte(int reps) {
     44         mParcel.setDataCapacity(reps);
     45         for (int i = 0; i < reps; i++) {
     46             mParcel.readByte();
     47         }
     48     }
     49 
     50     public void timeWriteInt(int reps) {
     51         final int val = 0xF;
     52         for (int i = 0; i < reps; i++) {
     53             mParcel.writeInt(val);
     54         }
     55     }
     56 
     57     public void timeReadInt(int reps) {
     58         mParcel.setDataCapacity(reps << 2);
     59         for (int i = 0; i < reps; i++) {
     60             mParcel.readInt();
     61         }
     62     }
     63 
     64     public void timeWriteLong(int reps) {
     65         final long val = 0xF;
     66         for (int i = 0; i < reps; i++) {
     67             mParcel.writeLong(val);
     68         }
     69     }
     70 
     71     public void timeReadLong(int reps) {
     72         mParcel.setDataCapacity(reps << 3);
     73         for (int i = 0; i < reps; i++) {
     74             mParcel.readLong();
     75         }
     76     }
     77 }
     78