Return-Path: Delivered-To: apmail-lucene-java-commits-archive@www.apache.org Received: (qmail 53608 invoked from network); 3 Aug 2006 19:27:14 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 3 Aug 2006 19:27:14 -0000 Received: (qmail 19920 invoked by uid 500); 3 Aug 2006 19:27:11 -0000 Delivered-To: apmail-lucene-java-commits-archive@lucene.apache.org Received: (qmail 19900 invoked by uid 500); 3 Aug 2006 19:27:10 -0000 Mailing-List: contact java-commits-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: java-dev@lucene.apache.org Delivered-To: mailing list java-commits@lucene.apache.org Received: (qmail 19889 invoked by uid 99); 3 Aug 2006 19:27:10 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Aug 2006 12:27:10 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Aug 2006 12:27:09 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id B801C1A981A; Thu, 3 Aug 2006 12:26:49 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r428488 - /lucene/java/trunk/src/test/org/apache/lucene/index/TestTermdocPerf.java Date: Thu, 03 Aug 2006 19:26:49 -0000 To: java-commits@lucene.apache.org From: yonik@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060803192649.B801C1A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: yonik Date: Thu Aug 3 12:26:48 2006 New Revision: 428488 URL: http://svn.apache.org/viewvc?rev=428488&view=rev Log: performance test for TermDoc iteration speed Added: lucene/java/trunk/src/test/org/apache/lucene/index/TestTermdocPerf.java Added: lucene/java/trunk/src/test/org/apache/lucene/index/TestTermdocPerf.java URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestTermdocPerf.java?rev=428488&view=auto ============================================================================== --- lucene/java/trunk/src/test/org/apache/lucene/index/TestTermdocPerf.java (added) +++ lucene/java/trunk/src/test/org/apache/lucene/index/TestTermdocPerf.java Thu Aug 3 12:26:48 2006 @@ -0,0 +1,115 @@ +package org.apache.lucene.index; + +/** + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +import junit.framework.TestCase; +import org.apache.lucene.store.Directory; +import org.apache.lucene.store.RAMDirectory; +import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.analysis.TokenStream; +import org.apache.lucene.analysis.Token; +import org.apache.lucene.document.Document; +import org.apache.lucene.document.Field; + +import java.io.Reader; +import java.io.IOException; +import java.util.Random; + +/** + * @author yonik + * @version $Id$ + */ + +class RepeatingTokenStream extends TokenStream { + public int num; + Token t; + + public RepeatingTokenStream(String val) { + t = new Token(val,0,val.length()); + } + + public Token next() throws IOException { + return --num<0 ? null : t; + } +} + + +public class TestTermdocPerf extends TestCase { + + void addDocs(Directory dir, final int ndocs, String field, final String val, final int maxTF, final float percentDocs) throws IOException { + final Random random = new Random(0); + final RepeatingTokenStream ts = new RepeatingTokenStream(val); + + Analyzer analyzer = new Analyzer() { + public TokenStream tokenStream(String fieldName, Reader reader) { + if (random.nextFloat() < percentDocs) ts.num = random.nextInt(maxTF)+1; + else ts.num=0; + return ts; + } + }; + + Document doc = new Document(); + doc.add(new Field(field,val, Field.Store.NO, Field.Index.NO_NORMS)); + IndexWriter writer = new IndexWriter(dir, analyzer, true); + writer.setMaxBufferedDocs(100); + writer.setMergeFactor(100); + + for (int i=0; i