use of org.noggit.CharArr in project lucene-solr by apache.
the class SolrTestCaseJ4 method jsonDelQ.
/** Creates a JSON deleteByQuery command */
public static String jsonDelQ(String... queries) {
CharArr out = new CharArr();
try {
out.append('{');
boolean first = true;
for (Object q : queries) {
if (first)
first = false;
else
out.append(',');
out.append("\"delete\":{\"query\":");
out.append(JSONUtil.toJSON(q));
out.append('}');
}
out.append('}');
} catch (IOException e) {
// should never happen
}
return out.toString();
}
use of org.noggit.CharArr in project lucene-solr by apache.
the class TestJavaBinCodec method testPerf.
private void testPerf() throws InterruptedException {
final ArrayList<JavaBinCodec.StringBytes> l = new ArrayList<>();
Cache<JavaBinCodec.StringBytes, String> cache = null;
/* cache = new ConcurrentLRUCache<JavaBinCodec.StringBytes,String>(10000, 9000, 10000, 1000, false, true, null){
@Override
public String put(JavaBinCodec.StringBytes key, String val) {
l.add(key);
return super.put(key, val);
}
};*/
Runtime.getRuntime().gc();
printMem("before cache init");
Cache<JavaBinCodec.StringBytes, String> cache1 = new MapBackedCache<>(new HashMap<>());
final JavaBinCodec.StringCache STRING_CACHE = new JavaBinCodec.StringCache(cache1);
// STRING_CACHE = new JavaBinCodec.StringCache(cache);
byte[] bytes = new byte[0];
JavaBinCodec.StringBytes stringBytes = new JavaBinCodec.StringBytes(null, 0, 0);
for (int i = 0; i < 10000; i++) {
String s = String.valueOf(random().nextLong());
int end = s.length();
int maxSize = end * 4;
if (bytes == null || bytes.length < maxSize)
bytes = new byte[maxSize];
int sz = ByteUtils.UTF16toUTF8(s, 0, end, bytes, 0);
STRING_CACHE.get(stringBytes.reset(bytes, 0, sz));
}
printMem("after cache init");
RTimer timer = new RTimer();
final int ITERS = 1000000;
int THREADS = 10;
runInThreads(THREADS, () -> {
JavaBinCodec.StringBytes stringBytes1 = new JavaBinCodec.StringBytes(new byte[0], 0, 0);
for (int i = 0; i < ITERS; i++) {
JavaBinCodec.StringBytes b = l.get(i % l.size());
stringBytes1.reset(b.bytes, 0, b.bytes.length);
if (STRING_CACHE.get(stringBytes1) == null)
throw new RuntimeException("error");
}
});
printMem("after cache test");
System.out.println("time taken by LRUCACHE " + timer.getTime());
timer = new RTimer();
runInThreads(THREADS, () -> {
String a = null;
CharArr arr = new CharArr();
for (int i = 0; i < ITERS; i++) {
JavaBinCodec.StringBytes sb = l.get(i % l.size());
arr.reset();
ByteUtils.UTF8toUTF16(sb.bytes, 0, sb.bytes.length, arr);
a = arr.toString();
}
});
printMem("after new string test");
System.out.println("time taken by string creation " + timer.getTime());
}
use of org.noggit.CharArr in project lucene-solr by apache.
the class SolrTestCaseJ4 method jsonAdd.
/** Creates a JSON add command from a SolrInputDocument list. Doesn't currently handle boosts. */
public static String jsonAdd(SolrInputDocument... docs) {
CharArr out = new CharArr();
try {
out.append('[');
boolean firstField = true;
for (SolrInputDocument doc : docs) {
if (firstField)
firstField = false;
else
out.append(',');
out.append(json(doc));
}
out.append(']');
} catch (IOException e) {
// should never happen
}
return out.toString();
}
use of org.noggit.CharArr in project lucene-solr by apache.
the class TestDelegationTokenResponse method getMapJson.
private String getMapJson(String key, Object value) {
CharArr out = new CharArr();
JSONWriter w = new JSONWriter(out, 2);
Map<String, Object> map = new HashMap<String, Object>();
map.put(key, value);
w.write(map);
return out.toString();
}
Aggregations