FileDocCategorySizeDatePackage
SynchTime.javaAPI DocExample2620Wed Feb 23 17:14:30 GMT 2000tuning.threads

SynchTime

public class SynchTime extends Object

Fields Summary
long
SEED
static tuning.unpublishable.Random
Rand
static SynchTime
Other
static boolean
Switch
int
num
Constructors Summary
Methods Summary
public booleanequals(java.lang.Object o)


     
  
    return ((SynchTime) o).num == num;
  
public static voidmain(java.lang.String[] args)

    int repeat = 10000000;
    SynchTime inst = new SynchTime();
    inst.main1(repeat);
    inst.main2(repeat);
    inst.main3(repeat);
    inst.main4(repeat);
    inst.main1(repeat);
    inst.main4(repeat);
    inst.main3(repeat);
    inst.main2(repeat);
  
public voidmain1(int repeat)

    Rand = new Random(SEED);
    Switch = false;
    num = 0;
    int count = 0;
    long time = System.currentTimeMillis();
    for (int i = repeat; i > 0; i--)
    {
      if(Switch)
        num = Rand.nextInt();
      else
        num = 0;
      Switch = !Switch;
      if (Other.equals(this))
        count++;
    }
    System.out.println("inlined took " + (System.currentTimeMillis() - time) + " count = " + count);
  
public voidmain2(int repeat)

    Rand = new Random(SEED);
    Switch = false;
    num = 0;
    int count = 0;
    long time = System.currentTimeMillis();
    for (int i = repeat; i > 0; i--)
      if (unsyncTest())
        count++;
    System.out.println("unsyncTest took " + (System.currentTimeMillis() - time) + " count = " + count);
  
public voidmain3(int repeat)

    Rand = new Random(SEED);
    Switch = false;
    num = 0;
    int count = 0;
    long time = System.currentTimeMillis();
    for (int i = repeat; i > 0; i--)
      if (syncTest())
        count++;
    System.out.println("syncTest took " + (System.currentTimeMillis() - time) + " count = " + count);
  
public voidmain4(int repeat)

    Rand = new Random(SEED);
    Switch = false;
    num = 0;
    int count = 0;
    long time = System.currentTimeMillis();
    synchronized(this)
    {
      for (int i = repeat; i > 0; i--)
        if (unsyncTest())
          count++;
    }
    System.out.println("sync unsyncTest took " + (System.currentTimeMillis() - time) + " count = " + count);
  
public synchronized booleansyncTest()

    if(Switch)
      num = Rand.nextInt();
    else
      num = 0;
    Switch = !Switch;
    return Other.equals(this);
  
public booleanunsyncTest()

    if(Switch)
      num = Rand.nextInt();
    else
      num = 0;
    Switch = !Switch;
    return Other.equals(this);