Class ThreadSpeedTest

java.lang.Object
com.singularsys.jepexamples.diagnostics.ThreadSpeedTest
Direct Known Subclasses:
RpThreadSpeed, ThreadSafeSpeedTest

public class ThreadSpeedTest extends Object
Tests evaluation using multiple threads. Subclasses can override methods to change how threads are constructed.
Author:
Richard Morris
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    A thread which evaluates an expression multiple times.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected Node
    Parsed expression
    protected Jep
    Base Jep instance
    static final int
    Number of loops to run
    static final int
    Maximum number of threads to test.
    static final int
    Number of terms in the expressions
    static final int
    Total number of iterations for each step
    protected String
    Name of variable
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Do nothing constructor for use by subclasses
     
    ThreadSpeedTest(String expression, String varName)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Prints some basic info about the expression
    static String
    getExpression(int nTerms)
    Gets an expression to evaluate using an approximation to log "x^1/1-x^2/2+x^3/3-..."
    int
    go(int nThreads, int nItts, double minValue, double maxValue)
    Create and run threads.
    void
    loop(int maxThreads, int totalItts, int nLoops)
    Repeatedly execute threads.
    static void
    main(String[] args)
    Run the thread test program.
    makeThread(int index, double min, double max, int nItts)
    Make a thread to evaluate an expression multiple times.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • N_TERMS

      public static final int N_TERMS
      Number of terms in the expressions
      See Also:
    • MAX_LOOPS

      public static final int MAX_LOOPS
      Number of loops to run
      See Also:
    • TOTAL_ITTS

      public static final int TOTAL_ITTS
      Total number of iterations for each step
      See Also:
    • MAX_THREADS

      public static final int MAX_THREADS
      Maximum number of threads to test.
      See Also:
    • baseJep

      protected Jep baseJep
      Base Jep instance
    • base

      protected Node base
      Parsed expression
    • varName

      protected String varName
      Name of variable
  • Constructor Details

    • ThreadSpeedTest

      protected ThreadSpeedTest()
      Do nothing constructor for use by subclasses
    • ThreadSpeedTest

      public ThreadSpeedTest(String expression, String varName) throws ParseException
      Parameters:
      expression - the expression
      varName - name of the variable
      Throws:
      ParseException
  • Method Details

    • go

      public int go(int nThreads, int nItts, double minValue, double maxValue) throws JepException
      Create and run threads. Calls makeThread to construct threads, then runs the threads simultaneously and calculated total time of execution.
      Parameters:
      nThreads - number of threads to run
      nItts - number of iterations per thread
      minValue - minimum variable value
      maxValue - maximum variable value
      Returns:
      time taken to evaluate, does not include construction time
      Throws:
      JepException
    • makeThread

      public Thread makeThread(int index, double min, double max, int nItts) throws JepException
      Make a thread to evaluate an expression multiple times. Can be overridden to change how threads are created. This version uses ThreadSpeedTest.EvaluationThread
      Parameters:
      index - the number of this thread
      min - minimum value for variable
      max - maximum value for variable
      nItts - number of iterations
      Returns:
      the thread
      Throws:
      JepException
    • loop

      public void loop(int maxThreads, int totalItts, int nLoops)
      Repeatedly execute threads. First run with 1 thread, then with 2 thread and so on upto maxThreads threads. The total iterations are divided among threads. Repeats the whole process nLoops times. Time statistics are gathered from all but the first loop and summary statistics printed on completion.
      Parameters:
      maxThreads -
      totalItts -
      nLoops - number of times
    • analyze

      public void analyze()
      Prints some basic info about the expression
    • getExpression

      public static String getExpression(int nTerms)
      Gets an expression to evaluate using an approximation to log "x^1/1-x^2/2+x^3/3-..."
      Parameters:
      nTerms - number of terms
      Returns:
      a string with the expression
    • main

      public static void main(String[] args)
      Run the thread test program.
      Parameters:
      args - If specified args[0] is maximum number of threads, args[1] is total number of iterations