Class ThreadSpeedTest
java.lang.Object
com.singularsys.jepexamples.diagnostics.ThreadSpeedTest
- Direct Known Subclasses:
RpThreadSpeed,ThreadSafeSpeedTest
Tests evaluation using multiple threads.
Subclasses can override methods to change how threads are constructed.
- Author:
- Richard Morris
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA thread which evaluates an expression multiple times. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected NodeParsed expressionprotected JepBase Jep instancestatic final intNumber of loops to runstatic final intMaximum number of threads to test.static final intNumber of terms in the expressionsstatic final intTotal number of iterations for each stepprotected StringName of variable -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDo nothing constructor for use by subclassesThreadSpeedTest(String expression, String varName) -
Method Summary
Modifier and TypeMethodDescriptionvoidanalyze()Prints some basic info about the expressionstatic StringgetExpression(int nTerms) Gets an expression to evaluate using an approximation to log "x^1/1-x^2/2+x^3/3-..."intgo(int nThreads, int nItts, double minValue, double maxValue) Create and run threads.voidloop(int maxThreads, int totalItts, int nLoops) Repeatedly execute threads.static voidRun the thread test program.makeThread(int index, double min, double max, int nItts) Make a thread to evaluate an expression multiple times.
-
Field Details
-
N_TERMS
public static final int N_TERMSNumber of terms in the expressions- See Also:
-
MAX_LOOPS
public static final int MAX_LOOPSNumber of loops to run- See Also:
-
TOTAL_ITTS
public static final int TOTAL_ITTSTotal number of iterations for each step- See Also:
-
MAX_THREADS
public static final int MAX_THREADSMaximum number of threads to test.- See Also:
-
baseJep
Base Jep instance -
base
Parsed expression -
varName
Name of variable
-
-
Constructor Details
-
ThreadSpeedTest
protected ThreadSpeedTest()Do nothing constructor for use by subclasses -
ThreadSpeedTest
- Parameters:
expression- the expressionvarName- name of the variable- Throws:
ParseException
-
-
Method Details
-
go
Create and run threads. CallsmakeThreadto 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
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
-
analyze
public void analyze()Prints some basic info about the expression -
getExpression
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
Run the thread test program.- Parameters:
args- If specified args[0] is maximum number of threads, args[1] is total number of iterations
-