SUNLibraryPlugin.java
/* $Id: SUNLibraryPlugin.java.html 241 2004-12-15 16:22:42Z bkarak $ */ 
package org.benchmark.plugin; 
 
import java.util.regex.*; 
 
public class SUNLibraryPlugin implements LibraryPlugin { 
    /** 
     * Perform a full match attempt for a given set of regular expression and data. 
     * 
     * @param regularExpression 
     * @param data 
     * @return True upon sucess, false otherwise. 
     */ 
    public boolean match(String regularExpression, String data) { 
        try { 
            return Pattern.matches(regularExpression, data); 
        } catch (Exception e) { 
            return false; 
        } 
    } 
 
    /** 
     * Performs an iteration benchmark for a given regular expression / data. 
     * 
     * @param regularExpression 
     * @param data 
     * @param iterations 
     * @return The time ellapsed for the iterations (in miliseconds) 
     * @see System.currentTimeMillis() 
     */ 
    public long iterationBenchmark(String regularExpression, String data, int iterations) { 
        if(!match(regularExpression,data)){ return MATCH_ERROR;} 
 
        Pattern pat = Pattern.compile(regularExpression); 
        Matcher mat = pat.matcher(data); 
 
        long start = System.currentTimeMillis(); 
        for(int counter = 0;counter < iterations;counter++) { 
            mat.matches(); 
        } 
        long end = System.currentTimeMillis(); 
 
        return (end - start); 
    } 
 
}