Changeset 25

Show
Ignore:
Timestamp:
09/17/08 16:19:53 (3 years ago)
Author:
fumanchu
Message:

New timing(call, number) function to assert call times.

Location:
trunk/epic
Files:
1 added
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/epic/epic.sql

    r24 r25  
    937937$$ LANGUAGE plpgsql; 
    938938 
     939 
     940CREATE OR REPLACE FUNCTION test.timing(call text, number int) RETURNS interval AS $$ 
     941-- Return an interval encompassing 'number' runs of the given call. 
     942-- If 'number' is NULL or omitted, it defaults to 1000000. 
     943DECLARE 
     944  v_call   text; 
     945  v_number int; 
     946  start    timestamp with time zone; 
     947BEGIN 
     948  v_call := test.statement(call); 
     949  v_number := number; 
     950  IF number IS NULL THEN v_number := 1000000; END IF; 
     951  -- Mustn't use now() here since that value is fixed for the entire transaction. 
     952  start := clock_timestamp(); 
     953  FOR i IN 1..v_number 
     954  LOOP 
     955    EXECUTE v_call; 
     956  END LOOP; 
     957  -- We grab the total clock time outside the loop. It's a toss-up whether the loop 
     958  -- overhead outweighs assignment overhead if we accumulated the time inside the loop; 
     959  -- therefore I chose "outside" since it makes the whole run faster. ;) 
     960  RETURN (clock_timestamp() - start); 
     961END; 
     962$$ LANGUAGE plpgsql; 
     963 
     964 
     965CREATE OR REPLACE FUNCTION test.timing(call text) RETURNS interval AS $$ 
     966-- Return an interval encompassing 1,000 runs of the given call. 
     967BEGIN 
     968  RETURN test.timing(call, NULL); 
     969END; 
     970$$ LANGUAGE plpgsql;