-- File: DBTimings.mesa
-- Last Edited by: Cattell, April 18, 1983 7:24 pm

DIRECTORY DB;

DBTimings: PROGRAM IMPORTS DB =

BEGIN OPEN DB;

mySeg: DB.Segment = $Test;
Person: Domain;
friend: Relation;
friendOf, friendIs: Attribute;
e1, e2: Entity;

TestLookup: PROC =
  BEGIN
  FOR i: INT IN (0..1000] DO
    []← DeclareRelship[friend, LIST[[friendOf, e1]], OldOnly] ENDLOOP;
  CloseTransaction[TransactionOf[mySeg]];
  END;

TestGetF: PROC =
  BEGIN t: Relship ← DeclareRelship[friend, LIST[[friendOf, e1]], OldOnly];
  FOR i: INT IN (0..1000] DO
    []← GetF[t, friendOf]  ENDLOOP;
  CloseTransaction[TransactionOf[mySeg]];
  END;

TestSetF: PROC =
  BEGIN t: Relship ← DeclareRelship[friend, LIST[[friendOf, e1]], OldOnly];
  FOR i: INT IN (0..1000] DO
    []← SetF[t, friendOf, e1]  ENDLOOP;
  CloseTransaction[TransactionOf[mySeg]];
  END;

TestGetFS: PROC =
  BEGIN t: Relship ← DeclareRelship[friend, LIST[[friendOf, e1]], OldOnly];
  FOR i: INT IN (0..1000] DO
    []← GetFS[t, friendOf]  ENDLOOP;
  CloseTransaction[TransactionOf[mySeg]];
  END;

TestSetFS: PROC =
  BEGIN t: Relship ← DeclareRelship[friend, LIST[[friendOf, e1]], OldOnly];
  FOR i: INT IN (0..1000] DO
    []← SetFS[t, friendOf, "Foo"]  ENDLOOP;
  CloseTransaction[TransactionOf[mySeg]];
  END;

Initialize: PROC =
  -- linked un-indexed field
  BEGIN 
  DB.OpenTransaction[mySeg];
  Person← DeclareDomain["Person", mySeg];
  friend← DeclareRelation["friend", mySeg];
  friendOf← DeclareAttribute[friend, "of", Person];
  friendIs← DeclareAttribute[friend, "is", Person];
  e1← DeclareEntity[Person, "Foo"];
  e2← DeclareEntity[Person, "Baz"];
  []← DeclareRelship[friend, LIST[[friendOf, e1], [friendIs, e2]]];
  END;
  
Initialize2: PROC =
  -- indexed un-linked field
  BEGIN 
  DB.OpenTransaction[mySeg];
  Person← DeclareDomain["Person", mySeg];
  friend← DeclareRelation["friend", mySeg];
  friendOf← DeclareAttribute[friend, "of", Person,,, Unlinked];
  friendIs← DeclareAttribute[friend, "is", Person,,, Unlinked];
  []← DeclareIndex[friend, LIST[friendOf], NewOrOld];
  e1← DeclareEntity[Person, "Foo"];
  e2← DeclareEntity[Person, "Baz"];
  []← DeclareRelship[friend, LIST[[friendOf, e1], [friendIs, e2]]];
  END;
  
Initialize3: PROC =
  -- un-indexed un-linked field
  BEGIN 
  DB.OpenTransaction[mySeg];
  Person← DeclareDomain["Person", mySeg];
  friend← DeclareRelation["friend", mySeg];
  friendOf← DeclareAttribute[friend, "of", Person,,, Unlinked];
  friendIs← DeclareAttribute[friend, "is", Person,,, Unlinked];
  e1← DeclareEntity[Person, "Foo"];
  e2← DeclareEntity[Person, "Baz"];
  []← DeclareRelship[friend, LIST[[friendOf, e1], [friendIs, e2]]];
  END;
  

DB.Initialize[];
DB.DeclareSegment["[Local]Test.segment", mySeg, ,, NewOnly];


END.