KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nfunk > jepexamples > LargeExpressionTest


1 /*****************************************************************************
2
3 JEP - Java Math Expression Parser 2.3.0
4       October 3 2004
5       (c) Copyright 2004, Nathan Funk and Richard Morris
6       See LICENSE.txt for license information.
7
8 *****************************************************************************/

9
10 package org.nfunk.jepexamples;
11
12 import java.util.*;
13
14 import org.nfunk.jep.JEP;
15
16 /**
17  * This example tests how the evaluation time is influenced by the size of the
18  * expression and symbol table.
19  */

20 public class LargeExpressionTest {
21     public static void main(String JavaDoc args[]) {
22         int nEvals = 500;
23         int nVars = 1000;
24         Date start, finish;
25         String JavaDoc str = "";
26         
27         JEP myParser = new JEP();
28
29         // Test small symbol table
30
for (int i=0; i<10; i++) {
31             myParser.addVariable("v"+i, 0);
32             str += "+" + "v" + i;
33         }
34         myParser.parseExpression(str);
35         System.out.print("Evaluating with small symbol table... ");
36         start = new Date();
37         for (int i=0; i<nEvals; i++) {
38             myParser.getValue();
39         }
40         finish = new Date();
41         System.out.println("done.");
42         System.out.println("Time: " +
43                             (finish.getTime() - start.getTime()));
44         
45         // Test large symbol table
46
str = "";
47         for (int i=0; i<nVars; i++) {
48             myParser.addVariable("v" + i, 0);
49             str += "+" + "v" + i;
50         }
51         myParser.parseExpression(str);
52         System.out.print("Evaluating with large symbol table... ");
53         start = new Date();
54         for (int i=0; i<nEvals; i++) {
55             myParser.getValue();
56         }
57         finish = new Date();
58         System.out.println("done.");
59         System.out.println("Time: " +
60                             (finish.getTime() - start.getTime()));
61     }
62 }
63
Popular Tags