Hi I am trying to find the number of rectangles per sec in three
different size rectangles. I did find it though. But the only problem
is that I see all the rectangles after it ran the program completely.
But I would like to have rectangles drawn, when I call
canvas.drawRect(rec1,paint); function.
I am also looking to keep the old rectangles on the screen while new
ones are drawn.
I tried with lots of different options nothing worked. To display the
rectangles
Can anybody show me the direction to which way to go ?
Thanks in advance.
Cheers
Kishore Srimat
package com.Benchmark.Rectangle;
import java.util.TimerTask;
import android.R.anim;
import android.app.Activity;
import android.app.AlertDialog;
import android.graphics.drawable.shapes.*;
import android.os.Bundle;
import android.content.Context;
import android.graphics.*;
import android.view.View;
import android.view.animation.Animation;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class Benchmark_Rectangle extends Activity {
DemoView demoview;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
demoview = new DemoView(this);
setContentView(demoview);
}
int getRandom(int min1 , int max1)
{
return (int) ((int)(Math.round(Math.random()*(max1-min1)))
+min1);
}
private class DemoView extends View{
public DemoView(Context context){
super(context);
}
@Override protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
long beforedrawing = 0;
// remember: y increases from top to bottom
// x increases from left to right
int i = 0;
int left = getLeft();
int top = getTop();
int right = getRight();
int bottom = getBottom();
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL);
// make the entire canvas white
paint.setColor(Color.WHITE);
canvas.drawPaint(paint);
int LoNumber = 0;
int HiNumber = 255;
long startwithoutrect = System.currentTimeMillis();
for(i=0;i<=10000; i++)
{
int myRandomNumber_Ra = getRandom(LoNumber,HiNumber);
int myRandomNumber_Rr= getRandom(LoNumber,HiNumber);
int myRandomNumber_Rg = getRandom(LoNumber,HiNumber);
int myRandomNumber_Rb = getRandom(LoNumber,HiNumber);
paint.setARGB(myRandomNumber_Ra, myRandomNumber_Rr,
myRandomNumber_Rg, myRandomNumber_Rb);
int sizex= 50;
int sizey = 50;
int x = getRandom(left, right-sizex);
int y = getRandom(top, bottom-sizey);
}
long stopwithoutrect = System.currentTimeMillis();
//
******************************************************************************************************************//
long startwithlargerect = System.currentTimeMillis();
for(i=0;i<=10000; i++)
{
int myRandomNumber_Ra = getRandom(LoNumber,HiNumber);
int myRandomNumber_Rr= getRandom(LoNumber,HiNumber);
int myRandomNumber_Rg = getRandom(LoNumber,HiNumber);
int myRandomNumber_Rb = getRandom(LoNumber,HiNumber);
paint.setARGB(myRandomNumber_Ra, myRandomNumber_Rr,
myRandomNumber_Rg, myRandomNumber_Rb);
int sizex=right;//320;
int sizey = bottom;//430;
int x = getRandom(left, right-sizex);
int y = getRandom(top, bottom-sizey);
Rect rec1 = new Rect(x/*left*/, y/*top*/, x +
sizex/*right*/, y
+ sizey/*bottom*/);
//if(sx != 0 && sy != 0)
canvas.drawRect(rec1,paint);
// Animation = new Benchmark_Rectangle();
// Animation.Initalise(Bitmap.decodeResource(res,
R.drawable.idle), 200, 150, 5, 5);
}
long stopwithlargerect = System.currentTimeMillis();
//
******************************************************************************************************************//
long startwithmediumrect = System.currentTimeMillis();
for(i=0;i<=10000; i++)
{
int myRandomNumber_Ra = getRandom(LoNumber,HiNumber);
int myRandomNumber_Rr= getRandom(LoNumber,HiNumber);
int myRandomNumber_Rg = getRandom(LoNumber,HiNumber);
int myRandomNumber_Rb = getRandom(LoNumber,HiNumber);
paint.setARGB(myRandomNumber_Ra, myRandomNumber_Rr,
myRandomNumber_Rg, myRandomNumber_Rb);
int sizex= 150;
int sizey = 150;
int x = getRandom(left, right-sizex);
int y = getRandom(top, bottom-sizey);
Rect rec1 = new Rect(x/*left*/, y/*top*/, x +
sizex/*right*/, y
+ sizey/*bottom*/);
//if(sx != 0 && sy != 0)
canvas.drawRect(rec1,paint);
}
long stopwithmediumrect = System.currentTimeMillis();
//
******************************************************************************************************************//
long startwithsmallrect = System.currentTimeMillis();
for(i=0;i<=10000; i++)
{
int myRandomNumber_Ra = getRandom(LoNumber,HiNumber);
int myRandomNumber_Rr= getRandom(LoNumber,HiNumber);
int myRandomNumber_Rg = getRandom(LoNumber,HiNumber);
int myRandomNumber_Rb = getRandom(LoNumber,HiNumber);
paint.setARGB(myRandomNumber_Ra, myRandomNumber_Rr,
myRandomNumber_Rg, myRandomNumber_Rb);
int sizex= 50;
int sizey = 50;
int x = getRandom(left, right-sizex);
int y = getRandom(top, bottom-sizey);
Rect rec1 = new Rect(x/*left*/, y/*top*/, x +
sizex/*right*/, y
+ sizey/*bottom*/);
//if(sx != 0 && sy != 0)
canvas.drawRect(rec1,paint);
}
long stopwithsmallrect = System.currentTimeMillis();
//
******************************************************************************************************************//
if(i >= 10000)
{
long exceptrect = (stopwithoutrect - startwithoutrect);
long totaltimeforsmallrect = ((stopwithsmallrect -
startwithsmallrect) - exceptrect);
long totaltimeformediumrect = ((stopwithmediumrect -
startwithmediumrect)-exceptrect);
long totaltimeforlargerect = ((stopwithlargerect -
startwithlargerect)-exceptrect);
float secssmallrect = (float) (totaltimeforsmallrect/
1000.0);
float secsmediumrect = (float) (totaltimeformediumrect/
1000.0);
float secslargerect = (float) (totaltimeforlargerect/
1000.0);
float noofsmallrectpersec = (float) (10000.00/
secssmallrect);
float noofmediumrectpersec = (float) (10000.00/
secsmediumrect);
float nooflargerectpersec = (float) (10000.00/
secslargerect);
android.util.Log.d("rect", " Number of small rectangles
per sec = " + (noofsmallrectpersec) + " secs");
android.util.Log.d("rect", " Number of medium rectangles
per sec = " + (noofmediumrectpersec) + " secs");
android.util.Log.d("rect", " Number of large rectangles
per sec = " + (nooflargerectpersec) + " secs");
AlertDialog.Builder ab=new
AlertDialog.Builder(Benchmark_Rectangle.this);
ab.setMessage(" Small rect per sec(50 x 50) = " +
(noofsmallrectpersec) + " Number of medium rectangles per sec =
" + (noofmediumrectpersec) + " Number of large rectangles per
sec = " + (nooflargerectpersec));
ab.setPositiveButton("ok", null);
ab.show();
}
}
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en