FilterComparison2public class FilterComparison2 extends Object
Fields Summary |
---|
static char[] | NewLine | static int | count | public static char[] | buf |
Methods Summary |
---|
public static void | cfilter(java.lang.String filter, java.lang.String filename, boolean print)
MatchReader2.filter(filter, filename, print);
| public static void | filter1(java.lang.String filter, java.lang.String filename, boolean print)
count = 0;
// BufferedReader rdr = new BufferedReader(new FileReader(filename));
BufferedReader rdr = new BufferedReader(new CharArrayReader(buf));
String line;
String ufilter = filter.toUpperCase();
while( (line = rdr.readLine()) != null)
{
if (line.toUpperCase().indexOf(ufilter) != -1)
{
count++;
if (print)
System.out.println(line);
}
}
System.out.println(count + " lines matched.");
rdr.close();
| public static void | filter2(java.lang.String filter, java.lang.String filename, boolean print)
count = 0;
// BufferedReader rdr = new BufferedReader(new FileReader(filename));
BufferedReader rdr = new BufferedReader(new CharArrayReader(buf));
String line;
int filterLength = filter.length();
while( (line = rdr.readLine()) != null)
{
for(int i = 0; i < line.length(); i++)
if (line.regionMatches(true, i, filter, 0, filterLength))
{
count++;
if (print)
System.out.println(line);
break;
}
}
System.out.println(count + " lines matched.");
rdr.close();
| public static void | filter3(java.lang.String filter, java.lang.String filename, boolean print)
count = 0;
Pattern p = Pattern.compile("^.*" + filter + ".*$", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
CharBuffer cbuff = CharBuffer.wrap(buf);
Matcher m = p.matcher(cbuff);
while( m.find() )
{
count++;
if (print)
System.out.println(m.group());
}
System.out.println(count + " lines matched.");
| public static void | main(java.lang.String[] args)
String NewLineStr = System.getProperty("line.separator");
NewLine = new char[NewLineStr.length()];
NewLineStr.getChars(0, NewLine.length, NewLine, 0);
test(args);
if (args.length > 2)
test(args);
| public static void | test(java.lang.String[] args)
try
{
if (buf == null)
{
File f = new File(args[1]);
buf = new char[(int) f.length()];
FileReader r = new FileReader(args[1]);
int len = 0, len2;
while( (len2 = r.read(buf,len,buf.length-len)) > 0) {len+=len2;}
if (len != buf.length) throw new Exception("Didn't read the whole file");
r.close();
}
long time = System.currentTimeMillis();
filter3(args[0], args[1], false);
time = System.currentTimeMillis() - time;
System.out.println("filter3 time (millis) = " + time);
System.gc();
System.gc();
System.gc();
System.gc();
time = System.currentTimeMillis();
filter1(args[0], args[1], false);
time = System.currentTimeMillis() - time;
System.out.println("filter1 time (millis) = " + time);
System.gc();
System.gc();
System.gc();
System.gc();
time = System.currentTimeMillis();
filter2(args[0], args[1], false);
time = System.currentTimeMillis() - time;
System.out.println("filter2 time (millis) = " + time);
System.gc();
System.gc();
System.gc();
System.gc();
time = System.currentTimeMillis();
cfilter(args[0], args[1], false);
time = System.currentTimeMillis() - time;
System.out.println("cfilter time (millis) = " + time);
System.gc();
System.gc();
System.gc();
System.gc();
}
catch(Exception e){e.printStackTrace();}
|
|