// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
public class Loops {
    public static final int SIZ = 10000;
    public static final int REP = 10000;
    private static final String BADCHARS = "<\"&'/>\\";
    public static boolean loopLongShort(String data) {
        for(int i = 0; i < data.length(); i++) {
            if(BADCHARS.indexOf(data.charAt(i)) >= 0) {
                return true;
            }
        }
        return false;
    }
    public static boolean loopShortLong(String data) {
        for(int i = 0; i < BADCHARS.length(); i++) {
            if(data.indexOf(BADCHARS.charAt(i)) >= 0) {
                return true;
            }
        }
        return false;
    }
    public static void main(String[] args) throws Exception {
        StringBuffer s = new StringBuffer();
        for(int i = 0; i < SIZ; i++) {
            s.append("A");
        }
        s.append("\\");
        String v = s.toString();
        long t1 = System.currentTimeMillis();
        for(int i = 0; i < REP; i++) {
            boolean hit = loopLongShort(v);
            if(!hit) throw new Exception("Not detected by long-short");
        }
        long t2 = System.currentTimeMillis();
        System.out.println("Long-short run: " + (t2 - t1)/1000.0 + " s");
        long t3 = System.currentTimeMillis();
        for(int i = 0; i < REP; i++) {
            boolean hit = loopShortLong(v);
            if(!hit) throw new Exception("Not detected by short-long");
        }
        long t4 = System.currentTimeMillis();
        System.out.println("Short-long run: " + (t4 - t3)/1000.0 + " s");
    }
}
