Class ThreadSpeedTest
- java.lang.Object
-
- com.singularsys.jepexamples.diagnostics.ThreadSpeedTest
-
- Direct Known Subclasses:
RpThreadSpeed
,ThreadSafeSpeedTest
public class ThreadSpeedTest extends java.lang.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
ThreadSpeedTest.EvaluationThread
A thread which evaluates an expression multiple times.
-
Field Summary
Fields Modifier and Type Field Description protected Node
base
Parsed expressionprotected Jep
baseJep
Base Jep instancestatic int
MAX_LOOPS
Number of loops to runstatic int
MAX_THREADS
Maximum number of threads to test.static int
N_TERMS
Number of terms in the expressionsstatic int
TOTAL_ITTS
Total number of iterations for each stepprotected java.lang.String
varName
Name of variable
-
Constructor Summary
Constructors Modifier Constructor Description protected
ThreadSpeedTest()
Do nothing constructor for use by subclassesThreadSpeedTest(java.lang.String expression, java.lang.String varName)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
analyize()
Prints some basic info about the expressionstatic java.lang.String
getExpression(int nTerms)
Gets a 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(java.lang.String[] args)
Run the thread test program.java.lang.Thread
makeThread(int index, double min, double max, int nItts)
Make a thread to evaluate an expression multiple times.
-
-
-
Field Detail
-
N_TERMS
public static final int N_TERMS
Number of terms in the expressions- See Also:
- Constant Field Values
-
MAX_LOOPS
public static final int MAX_LOOPS
Number of loops to run- See Also:
- Constant Field Values
-
TOTAL_ITTS
public static final int TOTAL_ITTS
Total number of iterations for each step- See Also:
- Constant Field Values
-
MAX_THREADS
public static final int MAX_THREADS
Maximum number of threads to test.- See Also:
- Constant Field Values
-
baseJep
protected Jep baseJep
Base Jep instance
-
base
protected Node base
Parsed expression
-
varName
protected java.lang.String varName
Name of variable
-
-
Constructor Detail
-
ThreadSpeedTest
protected ThreadSpeedTest()
Do nothing constructor for use by subclasses
-
ThreadSpeedTest
public ThreadSpeedTest(java.lang.String expression, java.lang.String varName) throws ParseException
- Parameters:
expression
- the expressionvarName
- name of the variable- Throws:
ParseException
-
-
Method Detail
-
go
public int go(int nThreads, int nItts, double minValue, double maxValue) throws JepException
Create and run threads. CallsmakeThread
to construct threads, then runs the threads simultaneously and calculated total time of execution.- Parameters:
nThreads
- number of threads to runnItts
- number of iterations per threadminValue
- minimum variable valuemaxValue
- maximum variable value- Returns:
- time taken to evaluate, does not include construction time
- Throws:
JepException
-
makeThread
public java.lang.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 usesThreadSpeedTest.EvaluationThread
- Parameters:
index
- the number of this threadmin
- minimum value for variablemax
- maximum value for variablenItts
- 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
-
analyize
public void analyize()
Prints some basic info about the expression
-
getExpression
public static java.lang.String getExpression(int nTerms)
Gets a 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(java.lang.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
-
-