public int TestSpeed() { // skip unless verbose if (!IsVerbose()) { return(0); } string s = "\uAC01\u0345"; CanonicalIterator it = new CanonicalIterator(s); double start, end; int x = 0; // just to keep code from optimizing away. int iterations = 10000; double slowDelta = 0; /* * CanonicalIterator slowIt = new CanonicalIterator(s); * slowIt.SKIP_ZEROS = false; * * start = System.currentTimeMillis(); * for (int i = 0; i < iterations; ++i) { * slowIt.setSource(s); * while (true) { * String item = slowIt.next(); * if (item == null) break; * x += item.length(); * } * } * end = System.currentTimeMillis(); * double slowDelta = (end-start) / iterations; * Logln("Slow iteration: " + slowDelta); */ start = Time.CurrentTimeMilliseconds(); for (int i = 0; i < iterations; ++i) { it.SetSource(s); while (true) { string item = it.Next(); if (item == null) { break; } x += item.Length; } } end = Time.CurrentTimeMilliseconds(); double fastDelta = (end - start) / iterations; Logln("Fast iteration: " + fastDelta + (slowDelta != 0 ? ", " + (fastDelta / slowDelta) : "")); return(x); }
private void CharacterTest(string s, int ch, CanonicalIterator it) { int mixedCounter = 0; int lastMixedCounter = -1; bool gotDecomp = false; bool gotComp = false; bool gotSource = false; string decomp = Normalizer.Decompose(s, false); string comp = Normalizer.Compose(s, false); // skip characters that don't have either decomp. // need quick test for this! if (s.Equals(decomp) && s.Equals(comp)) { return; } it.SetSource(s); while (true) { string item = it.Next(); if (item == null) { break; } if (item.Equals(s)) { gotSource = true; } if (item.Equals(decomp)) { gotDecomp = true; } if (item.Equals(comp)) { gotComp = true; } if ((mixedCounter & 0x7F) == 0 && (ch < 0xAD00 || ch > 0xAC00 + 11172)) { if (lastMixedCounter != mixedCounter) { Logln(""); lastMixedCounter = mixedCounter; } Logln("\t" + mixedCounter + "\t" + Hex(item) + (item.Equals(s) ? "\t(*original*)" : "") + (item.Equals(decomp) ? "\t(*decomp*)" : "") + (item.Equals(comp) ? "\t(*comp*)" : "") ); } } // check that zeros optimization doesn't mess up. /* * if (true) { * it.reset(); * itSet.clear(); * while (true) { * String item = it.next(); * if (item == null) break; * itSet.add(item); * } * slowIt.setSource(s); * slowItSet.clear(); * while (true) { * String item = slowIt.next(); * if (item == null) break; * slowItSet.add(item); * } * if (!itSet.equals(slowItSet)) { * errln("Zero optimization failure with " + getReadable(s)); * } * } */ mixedCounter++; if (!gotSource || !gotDecomp || !gotComp) { Errln("FAIL CanonicalIterator: " + s + " decomp: " + decomp + " comp: " + comp); it.Reset(); for (string item = it.Next(); item != null; item = it.Next()) { Err(item + " "); } Errln(""); } }