2 * Copyright (C) 2007 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package android.database;
19 import junit.framework.Assert;
21 import android.content.ContentValues;
22 import android.content.Context;
23 import android.database.Cursor;
24 import android.database.sqlite.SQLiteDatabase;
25 import android.provider.Contacts;
26 import android.provider.Contacts.People;
27 import android.test.PerformanceTestCase;
28 import android.test.TestCase;
31 import java.util.Random;
34 * Database Performance Tests
38 public class DatabasePerformanceTests {
40 public static String[] children() {
42 ContactReadingTest1.class.getName(),
43 Perf1Test.class.getName(),
44 Perf2Test.class.getName(),
45 Perf3Test.class.getName(),
46 Perf4Test.class.getName(),
47 Perf5Test.class.getName(),
48 Perf6Test.class.getName(),
49 Perf7Test.class.getName(),
50 Perf8Test.class.getName(),
51 Perf9Test.class.getName(),
52 Perf10Test.class.getName(),
53 Perf11Test.class.getName(),
54 Perf12Test.class.getName(),
55 Perf13Test.class.getName(),
56 Perf14Test.class.getName(),
57 Perf15Test.class.getName(),
58 Perf16Test.class.getName(),
59 Perf17Test.class.getName(),
60 Perf18Test.class.getName(),
61 Perf19Test.class.getName(),
62 Perf20Test.class.getName(),
63 Perf21Test.class.getName(),
64 Perf22Test.class.getName(),
65 Perf23Test.class.getName(),
66 Perf24Test.class.getName(),
67 Perf25Test.class.getName(),
68 Perf26Test.class.getName(),
69 Perf27Test.class.getName(),
70 Perf28Test.class.getName(),
71 Perf29Test.class.getName(),
72 Perf30Test.class.getName(),
73 Perf31Test.class.getName(),
77 public static abstract class PerformanceBase implements TestCase,
79 protected static final int CURRENT_DATABASE_VERSION = 42;
80 protected SQLiteDatabase mDatabase;
81 protected File mDatabaseFile;
82 protected Context mContext;
84 public void setUp(Context c) {
86 mDatabaseFile = new File("/tmp", "perf_database_test.db");
87 if (mDatabaseFile.exists()) {
88 mDatabaseFile.delete();
90 mDatabase = SQLiteDatabase.openOrCreateDatabase(mDatabaseFile.getPath(), null);
91 Assert.assertTrue(mDatabase != null);
92 mDatabase.setVersion(CURRENT_DATABASE_VERSION);
95 public void tearDown() {
97 mDatabaseFile.delete();
100 public boolean isPerformanceOnly() {
104 // These test can only be run once.
105 public int startPerformance(Intermediates intermediates) {
112 public String numberName(int number) {
115 if (number >= 1000) {
116 result += numberName((number / 1000)) + " thousand";
117 number = (number % 1000);
119 if (number > 0) result += " ";
123 result += ONES[(number / 100)] + " hundred";
124 number = (number % 100);
126 if (number > 0) result += " ";
130 result += TENS[(number / 10)];
131 number = (number % 10);
133 if (number > 0) result += " ";
137 result += ONES[number];
145 * Test reading all contact data.
147 public static class ContactReadingTest1 implements TestCase, PerformanceTestCase {
148 private static final String[] PEOPLE_PROJECTION = new String[] {
149 Contacts.People._ID, // 0
150 Contacts.People.PRIMARY_PHONE_ID, // 1
151 Contacts.People.TYPE, // 2
152 Contacts.People.NUMBER, // 3
153 Contacts.People.LABEL, // 4
154 Contacts.People.NAME, // 5
155 Contacts.People.PRESENCE_STATUS, // 6
158 private Cursor mCursor;
160 public void setUp(Context c) {
161 mCursor = c.getContentResolver().query(People.CONTENT_URI, PEOPLE_PROJECTION, null,
162 null, People.DEFAULT_SORT_ORDER);
165 public void tearDown() {
169 public boolean isPerformanceOnly() {
173 public int startPerformance(Intermediates intermediates) {
174 // This test can only be run once.
179 while (mCursor.moveToNext()) {
180 // Read out all of the data
184 mCursor.getString(3);
185 mCursor.getString(4);
186 mCursor.getString(5);
196 public static class Perf1Test extends PerformanceBase {
197 private static final int SIZE = 1000;
199 private String[] statements = new String[SIZE];
202 public void setUp(Context c) {
204 Random random = new Random(42);
206 for (int i = 0; i < SIZE; i++) {
207 int r = random.nextInt(100000);
209 "INSERT INTO t1 VALUES(" + i + "," + r + ",'"
210 + numberName(r) + "')";
214 .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))");
219 for (int i = 0; i < SIZE; i++) {
220 mDatabase.execSQL(statements[i]);
226 * Test 1000 inserts into and indexed table
229 public static class Perf2Test extends PerformanceBase {
230 private static final int SIZE = 1000;
232 private String[] statements = new String[SIZE];
235 public void setUp(Context c) {
237 Random random = new Random(42);
239 for (int i = 0; i < SIZE; i++) {
240 int r = random.nextInt(100000);
242 "INSERT INTO t1 VALUES(" + i + "," + r + ",'"
243 + numberName(r) + "')";
247 .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))");
248 mDatabase.execSQL("CREATE INDEX i1c ON t1(c)");
253 for (int i = 0; i < SIZE; i++) {
254 mDatabase.execSQL(statements[i]);
260 * 100 SELECTs without an index
263 public static class Perf3Test extends PerformanceBase {
264 private static final int SIZE = 100;
265 private static final String[] COLUMNS = {"count(*)", "avg(b)"};
267 private String[] where = new String[SIZE];
270 public void setUp(Context c) {
272 Random random = new Random(42);
275 .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))");
277 for (int i = 0; i < SIZE; i++) {
278 int r = random.nextInt(100000);
279 mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'"
280 + numberName(r) + "')");
283 for (int i = 0; i < SIZE; i++) {
285 int upper = (i + 10) * 100;
286 where[i] = "b >= " + lower + " AND b < " + upper;
292 for (int i = 0; i < SIZE; i++) {
294 .query("t1", COLUMNS, where[i], null, null, null, null);
300 * 100 SELECTs on a string comparison
303 public static class Perf4Test extends PerformanceBase {
304 private static final int SIZE = 100;
305 private static final String[] COLUMNS = {"count(*)", "avg(b)"};
307 private String[] where = new String[SIZE];
310 public void setUp(Context c) {
312 Random random = new Random(42);
315 .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))");
317 for (int i = 0; i < SIZE; i++) {
318 int r = random.nextInt(100000);
319 mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'"
320 + numberName(r) + "')");
323 for (int i = 0; i < SIZE; i++) {
324 where[i] = "c LIKE '" + numberName(i) + "'";
330 for (int i = 0; i < SIZE; i++) {
332 .query("t1", COLUMNS, where[i], null, null, null, null);
338 * 100 SELECTs with an index
341 public static class Perf5Test extends PerformanceBase {
342 private static final int SIZE = 100;
343 private static final String[] COLUMNS = {"count(*)", "avg(b)"};
345 private String[] where = new String[SIZE];
348 public void setUp(Context c) {
350 Random random = new Random(42);
353 .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))");
354 mDatabase.execSQL("CREATE INDEX i1b ON t1(b)");
356 for (int i = 0; i < SIZE; i++) {
357 int r = random.nextInt(100000);
358 mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'"
359 + numberName(r) + "')");
362 for (int i = 0; i < SIZE; i++) {
364 int upper = (i + 10) * 100;
365 where[i] = "b >= " + lower + " AND b < " + upper;
371 for (int i = 0; i < SIZE; i++) {
373 .query("t1", COLUMNS, where[i], null, null, null, null);
379 * INNER JOIN without an index
382 public static class Perf6Test extends PerformanceBase {
383 private static final int SIZE = 100;
384 private static final String[] COLUMNS = {"t1.a"};
387 public void setUp(Context c) {
389 Random random = new Random(42);
392 .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))");
394 .execSQL("CREATE TABLE t2(a INTEGER, b INTEGER, c VARCHAR(100))");
396 for (int i = 0; i < SIZE; i++) {
397 int r = random.nextInt(100000);
398 mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'"
399 + numberName(r) + "')");
402 for (int i = 0; i < SIZE; i++) {
403 int r = random.nextInt(100000);
404 mDatabase.execSQL("INSERT INTO t2 VALUES(" + i + "," + r + ",'"
405 + numberName(r) + "')");
411 mDatabase.query("t1 INNER JOIN t2 ON t1.b = t2.b", COLUMNS, null,
412 null, null, null, null);
417 * INNER JOIN without an index on one side
420 public static class Perf7Test extends PerformanceBase {
421 private static final int SIZE = 100;
422 private static final String[] COLUMNS = {"t1.a"};
425 public void setUp(Context c) {
427 Random random = new Random(42);
430 .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))");
432 .execSQL("CREATE TABLE t2(a INTEGER, b INTEGER, c VARCHAR(100))");
434 mDatabase.execSQL("CREATE INDEX i1b ON t1(b)");
436 for (int i = 0; i < SIZE; i++) {
437 int r = random.nextInt(100000);
438 mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'"
439 + numberName(r) + "')");
442 for (int i = 0; i < SIZE; i++) {
443 int r = random.nextInt(100000);
444 mDatabase.execSQL("INSERT INTO t2 VALUES(" + i + "," + r + ",'"
445 + numberName(r) + "')");
451 mDatabase.query("t1 INNER JOIN t2 ON t1.b = t2.b", COLUMNS, null,
452 null, null, null, null);
457 * INNER JOIN without an index on one side
460 public static class Perf8Test extends PerformanceBase {
461 private static final int SIZE = 100;
462 private static final String[] COLUMNS = {"t1.a"};
465 public void setUp(Context c) {
467 Random random = new Random(42);
470 .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))");
472 .execSQL("CREATE TABLE t2(a INTEGER, b INTEGER, c VARCHAR(100))");
474 mDatabase.execSQL("CREATE INDEX i1b ON t1(b)");
476 for (int i = 0; i < SIZE; i++) {
477 int r = random.nextInt(100000);
478 mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'"
479 + numberName(r) + "')");
482 for (int i = 0; i < SIZE; i++) {
483 int r = random.nextInt(100000);
484 mDatabase.execSQL("INSERT INTO t2 VALUES(" + i + "," + r + ",'"
485 + numberName(r) + "')");
491 mDatabase.query("t1 INNER JOIN t2 ON t1.c = t2.c", COLUMNS, null,
492 null, null, null, null);
497 * 100 SELECTs with subqueries. Subquery is using an index
500 public static class Perf9Test extends PerformanceBase {
501 private static final int SIZE = 100;
502 private static final String[] COLUMNS = {"t1.a"};
504 private String[] where = new String[SIZE];
507 public void setUp(Context c) {
509 Random random = new Random(42);
512 .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))");
514 .execSQL("CREATE TABLE t2(a INTEGER, b INTEGER, c VARCHAR(100))");
516 mDatabase.execSQL("CREATE INDEX i2b ON t2(b)");
518 for (int i = 0; i < SIZE; i++) {
519 int r = random.nextInt(100000);
520 mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'"
521 + numberName(r) + "')");
524 for (int i = 0; i < SIZE; i++) {
525 int r = random.nextInt(100000);
526 mDatabase.execSQL("INSERT INTO t2 VALUES(" + i + "," + r + ",'"
527 + numberName(r) + "')");
530 for (int i = 0; i < SIZE; i++) {
532 int upper = (i + 10) * 100;
534 "t1.b IN (SELECT t2.b FROM t2 WHERE t2.b >= " + lower
535 + " AND t2.b < " + upper + ")";
541 for (int i = 0; i < SIZE; i++) {
543 .query("t1", COLUMNS, where[i], null, null, null, null);
549 * 100 SELECTs on string comparison with Index
552 public static class Perf10Test extends PerformanceBase {
553 private static final int SIZE = 100;
554 private static final String[] COLUMNS = {"count(*)", "avg(b)"};
556 private String[] where = new String[SIZE];
559 public void setUp(Context c) {
561 Random random = new Random(42);
564 .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))");
565 mDatabase.execSQL("CREATE INDEX i3c ON t1(c)");
567 for (int i = 0; i < SIZE; i++) {
568 int r = random.nextInt(100000);
569 mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'"
570 + numberName(r) + "')");
573 for (int i = 0; i < SIZE; i++) {
574 where[i] = "c LIKE '" + numberName(i) + "'";
580 for (int i = 0; i < SIZE; i++) {
582 .query("t1", COLUMNS, where[i], null, null, null, null);
588 * 100 SELECTs on integer
591 public static class Perf11Test extends PerformanceBase {
592 private static final int SIZE = 100;
593 private static final String[] COLUMNS = {"b"};
595 private String[] where = new String[SIZE];
598 public void setUp(Context c) {
600 Random random = new Random(42);
603 .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))");
605 for (int i = 0; i < SIZE; i++) {
606 int r = random.nextInt(100000);
607 mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'"
608 + numberName(r) + "')");
615 for (int i = 0; i < SIZE; i++) {
616 mDatabase.query("t1", COLUMNS, null, null, null, null, null);
622 * 100 SELECTs on String
625 public static class Perf12Test extends PerformanceBase {
626 private static final int SIZE = 100;
627 private static final String[] COLUMNS = {"c"};
629 private String[] where = new String[SIZE];
632 public void setUp(Context c) {
634 Random random = new Random(42);
637 .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))");
639 for (int i = 0; i < SIZE; i++) {
640 int r = random.nextInt(100000);
641 mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'"
642 + numberName(r) + "')");
649 for (int i = 0; i < SIZE; i++) {
650 mDatabase.query("t1", COLUMNS, null, null, null, null, null);
656 * 100 SELECTs on integer with index
659 public static class Perf13Test extends PerformanceBase {
660 private static final int SIZE = 100;
661 private static final String[] COLUMNS = {"b"};
664 public void setUp(Context c) {
666 Random random = new Random(42);
669 .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))");
670 mDatabase.execSQL("CREATE INDEX i1b on t1(b)");
672 for (int i = 0; i < SIZE; i++) {
673 int r = random.nextInt(100000);
674 mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'"
675 + numberName(r) + "')");
682 for (int i = 0; i < SIZE; i++) {
683 mDatabase.query("t1", COLUMNS, null, null, null, null, null);
689 * 100 SELECTs on String with index
692 public static class Perf14Test extends PerformanceBase {
693 private static final int SIZE = 100;
694 private static final String[] COLUMNS = {"c"};
697 public void setUp(Context c) {
699 Random random = new Random(42);
702 .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))");
703 mDatabase.execSQL("CREATE INDEX i1c ON t1(c)");
705 for (int i = 0; i < SIZE; i++) {
706 int r = random.nextInt(100000);
707 mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'"
708 + numberName(r) + "')");
715 for (int i = 0; i < SIZE; i++) {
716 mDatabase.query("t1", COLUMNS, null, null, null, null, null);
722 * 100 SELECTs on String with starts with
725 public static class Perf15Test extends PerformanceBase {
726 private static final int SIZE = 100;
727 private static final String[] COLUMNS = {"c"};
728 private String[] where = new String[SIZE];
731 public void setUp(Context c) {
733 Random random = new Random(42);
736 .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))");
737 mDatabase.execSQL("CREATE INDEX i1c ON t1(c)");
739 for (int i = 0; i < SIZE; i++) {
740 int r = random.nextInt(100000);
741 mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'"
742 + numberName(r) + "')");
745 for (int i = 0; i < SIZE; i++) {
746 int r = random.nextInt(100000);
747 where[i] = "c LIKE '" + numberName(r).substring(0, 1) + "*'";
755 for (int i = 0; i < SIZE; i++) {
757 .query("t1", COLUMNS, where[i], null, null, null, null);
763 * 1000 Deletes on an indexed table
766 public static class Perf16Test extends PerformanceBase {
767 private static final int SIZE = 1000;
768 private static final String[] COLUMNS = {"c"};
771 public void setUp(Context c) {
773 Random random = new Random(42);
776 .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))");
777 mDatabase.execSQL("CREATE INDEX i3c ON t1(c)");
779 for (int i = 0; i < SIZE; i++) {
780 int r = random.nextInt(100000);
781 mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'"
782 + numberName(r) + "')");
789 for (int i = 0; i < SIZE; i++) {
790 mDatabase.delete("t1", null, null);
799 public static class Perf17Test extends PerformanceBase {
800 private static final int SIZE = 1000;
801 private static final String[] COLUMNS = {"c"};
804 public void setUp(Context c) {
806 Random random = new Random(42);
809 .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))");
811 for (int i = 0; i < SIZE; i++) {
812 int r = random.nextInt(100000);
813 mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'"
814 + numberName(r) + "')");
821 for (int i = 0; i < SIZE; i++) {
822 mDatabase.delete("t1", null, null);
828 * 1000 DELETE's without an index with where clause
831 public static class Perf18Test extends PerformanceBase {
832 private static final int SIZE = 1000;
833 private String[] where = new String[SIZE];
836 public void setUp(Context c) {
838 Random random = new Random(42);
841 .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))");
843 for (int i = 0; i < SIZE; i++) {
844 int r = random.nextInt(100000);
845 mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'"
846 + numberName(r) + "')");
849 for (int i = 0; i < SIZE; i++) {
851 int upper = (i + 10) * 100;
852 where[i] = "b >= " + lower + " AND b < " + upper;
858 for (int i = 0; i < SIZE; i++) {
859 mDatabase.delete("t1", where[i], null);
865 * 1000 DELETE's with an index with where clause
868 public static class Perf19Test extends PerformanceBase {
869 private static final int SIZE = 1000;
870 private String[] where = new String[SIZE];
873 public void setUp(Context c) {
875 Random random = new Random(42);
878 .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))");
879 mDatabase.execSQL("CREATE INDEX i1b ON t1(b)");
881 for (int i = 0; i < SIZE; i++) {
882 int r = random.nextInt(100000);
883 mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'"
884 + numberName(r) + "')");
887 for (int i = 0; i < SIZE; i++) {
889 int upper = (i + 10) * 100;
890 where[i] = "b >= " + lower + " AND b < " + upper;
896 for (int i = 0; i < SIZE; i++) {
897 mDatabase.delete("t1", where[i], null);
903 * 1000 update's with an index with where clause
906 public static class Perf20Test extends PerformanceBase {
907 private static final int SIZE = 1000;
908 private String[] where = new String[SIZE];
909 ContentValues[] mValues = new ContentValues[SIZE];
912 public void setUp(Context c) {
914 Random random = new Random(42);
917 .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))");
918 mDatabase.execSQL("CREATE INDEX i1b ON t1(b)");
920 for (int i = 0; i < SIZE; i++) {
921 int r = random.nextInt(100000);
922 mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'"
923 + numberName(r) + "')");
926 for (int i = 0; i < SIZE; i++) {
929 int upper = (i + 10) * 100;
930 where[i] = "b >= " + lower + " AND b < " + upper;
931 ContentValues b = new ContentValues(1);
940 for (int i = 0; i < SIZE; i++) {
941 mDatabase.update("t1", mValues[i], where[i], null);
947 * 1000 update's without an index with where clause
950 public static class Perf21Test extends PerformanceBase {
951 private static final int SIZE = 1000;
952 private String[] where = new String[SIZE];
953 ContentValues[] mValues = new ContentValues[SIZE];
956 public void setUp(Context c) {
958 Random random = new Random(42);
961 .execSQL("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100))");
963 for (int i = 0; i < SIZE; i++) {
964 int r = random.nextInt(100000);
965 mDatabase.execSQL("INSERT INTO t1 VALUES(" + i + "," + r + ",'"
966 + numberName(r) + "')");
969 for (int i = 0; i < SIZE; i++) {
972 int upper = (i + 10) * 100;
973 where[i] = "b >= " + lower + " AND b < " + upper;
974 ContentValues b = new ContentValues(1);
982 for (int i = 0; i < SIZE; i++) {
983 mDatabase.update("t1", mValues[i], where[i], null);
989 * 10000 inserts for an integer
992 public static class Perf22Test extends PerformanceBase {
993 private static final int SIZE = 10000;
994 ContentValues[] mValues = new ContentValues[SIZE];
997 public void setUp(Context c) {
999 Random random = new Random(42);
1002 .execSQL("CREATE TABLE t1(a INTEGER)");
1004 for (int i = 0; i < SIZE; i++) {
1005 int r = random.nextInt(100000);
1006 ContentValues b = new ContentValues(1);
1014 for (int i = 0; i < SIZE; i++) {
1015 mDatabase.insert("t1", null, mValues[i]);
1021 * 10000 inserts for an integer -indexed table
1024 public static class Perf23Test extends PerformanceBase {
1025 private static final int SIZE = 10000;
1026 ContentValues[] mValues = new ContentValues[SIZE];
1029 public void setUp(Context c) {
1031 Random random = new Random(42);
1034 .execSQL("CREATE TABLE t1(a INTEGER)");
1035 mDatabase.execSQL("CREATE INDEX i1a ON t1(a)");
1037 for (int i = 0; i < SIZE; i++) {
1038 int r = random.nextInt(100000);
1039 ContentValues b = new ContentValues(1);
1047 for (int i = 0; i < SIZE; i++) {
1048 mDatabase.insert("t1", null, mValues[i]);
1054 * 10000 inserts for a String
1057 public static class Perf24Test extends PerformanceBase {
1058 private static final int SIZE = 10000;
1059 ContentValues[] mValues = new ContentValues[SIZE];
1062 public void setUp(Context c) {
1064 Random random = new Random(42);
1067 .execSQL("CREATE TABLE t1(a VARCHAR(100))");
1069 for (int i = 0; i < SIZE; i++) {
1070 int r = random.nextInt(100000);
1071 ContentValues b = new ContentValues(1);
1072 b.put("a", numberName(r));
1079 for (int i = 0; i < SIZE; i++) {
1080 mDatabase.insert("t1", null, mValues[i]);
1086 * 10000 inserts for a String - indexed table
1089 public static class Perf25Test extends PerformanceBase {
1090 private static final int SIZE = 10000;
1091 ContentValues[] mValues = new ContentValues[SIZE];
1094 public void setUp(Context c) {
1096 Random random = new Random(42);
1099 .execSQL("CREATE TABLE t1(a VARCHAR(100))");
1100 mDatabase.execSQL("CREATE INDEX i1a ON t1(a)");
1102 for (int i = 0; i < SIZE; i++) {
1103 int r = random.nextInt(100000);
1104 ContentValues b = new ContentValues(1);
1105 b.put("a", numberName(r));
1112 for (int i = 0; i < SIZE; i++) {
1113 mDatabase.insert("t1", null, mValues[i]);
1120 * 10000 selects for a String -starts with
1123 public static class Perf26Test extends PerformanceBase {
1124 private static final int SIZE = 10000;
1125 private static final String[] COLUMNS = {"t3.a"};
1126 private String[] where = new String[SIZE];
1129 public void setUp(Context c) {
1131 Random random = new Random(42);
1134 .execSQL("CREATE TABLE t3(a VARCHAR(100))");
1136 for (int i = 0; i < SIZE; i++) {
1137 int r = random.nextInt(100000);
1138 mDatabase.execSQL("INSERT INTO t3 VALUES('"
1139 + numberName(r) + "')");
1142 for (int i = 0; i < SIZE; i++) {
1143 int r = random.nextInt(100000);
1144 where[i] = "a LIKE '" + numberName(r).substring(0, 1) + "*'";
1151 for (int i = 0; i < SIZE; i++) {
1152 mDatabase.query("t3", COLUMNS, where[i], null, null, null, null);
1158 * 10000 selects for a String - indexed table -starts with
1161 public static class Perf27Test extends PerformanceBase {
1162 private static final int SIZE = 10000;
1163 private static final String[] COLUMNS = {"t3.a"};
1164 private String[] where = new String[SIZE];
1167 public void setUp(Context c) {
1169 Random random = new Random(42);
1172 .execSQL("CREATE TABLE t3(a VARCHAR(100))");
1173 mDatabase.execSQL("CREATE INDEX i3a ON t3(a)");
1175 for (int i = 0; i < SIZE; i++) {
1176 int r = random.nextInt(100000);
1177 mDatabase.execSQL("INSERT INTO t3 VALUES('"
1178 + numberName(r) + "')");
1181 for (int i = 0; i < SIZE; i++) {
1182 int r = random.nextInt(100000);
1183 where[i] = "a LIKE '" + numberName(r).substring(0, 1) + "*'";
1190 for (int i = 0; i < SIZE; i++) {
1191 mDatabase.query("t3", COLUMNS, where[i], null, null, null, null);
1197 * 10000 selects for an integer -
1200 public static class Perf28Test extends PerformanceBase {
1201 private static final int SIZE = 10000;
1202 private static final String[] COLUMNS = {"t4.a"};
1203 private String[] where = new String[SIZE];
1206 public void setUp(Context c) {
1208 Random random = new Random(42);
1211 .execSQL("CREATE TABLE t4(a INTEGER)");
1213 for (int i = 0; i < SIZE; i++) {
1214 int r = random.nextInt(100000);
1215 mDatabase.execSQL("INSERT INTO t4 VALUES(" + r + ")");
1216 int lower = i * 100;
1217 int upper = (i + 10) * 100;
1218 where[i] = "a >= " + lower + " AND a < " + upper;
1224 for (int i = 0; i < SIZE; i++) {
1225 mDatabase.query("t4", COLUMNS, where[i], null, null, null, null);
1231 * 10000 selects for an integer -indexed table
1234 public static class Perf29Test extends PerformanceBase {
1235 private static final int SIZE = 10000;
1236 private static final String[] COLUMNS = {"t4.a"};
1237 private String[] where = new String[SIZE];
1240 public void setUp(Context c) {
1242 Random random = new Random(42);
1245 .execSQL("CREATE TABLE t4(a INTEGER)");
1246 mDatabase.execSQL("CREATE INDEX i4a ON t4(a)");
1248 for (int i = 0; i < SIZE; i++) {
1249 int r = random.nextInt(100000);
1250 mDatabase.execSQL("INSERT INTO t4 VALUES(" + r + ")");
1252 int lower = i * 100;
1253 int upper = (i + 10) * 100;
1254 where[i] = "a >= " + lower + " AND a < " + upper;
1261 for (int i = 0; i < SIZE; i++) {
1262 mDatabase.query("t4", COLUMNS, where[i], null, null, null, null);
1269 * 10000 selects for a String - contains 'e'
1272 public static class Perf30Test extends PerformanceBase {
1273 private static final int SIZE = 10000;
1274 private static final String[] COLUMNS = {"t3.a"};
1275 private String[] where = new String[SIZE];
1278 public void setUp(Context c) {
1280 Random random = new Random(42);
1283 .execSQL("CREATE TABLE t3(a VARCHAR(100))");
1285 for (int i = 0; i < SIZE; i++) {
1286 int r = random.nextInt(100000);
1287 mDatabase.execSQL("INSERT INTO t3 VALUES('"
1288 + numberName(r) + "')");
1291 for (int i = 0; i < SIZE; i++) {
1292 where[i] = "a LIKE '*e*'";
1299 for (int i = 0; i < SIZE; i++) {
1300 mDatabase.query("t3", COLUMNS, where[i], null, null, null, null);
1306 * 10000 selects for a String - contains 'e'-indexed table
1309 public static class Perf31Test extends PerformanceBase {
1310 private static final int SIZE = 10000;
1311 private static final String[] COLUMNS = {"t3.a"};
1312 private String[] where = new String[SIZE];
1315 public void setUp(Context c) {
1317 Random random = new Random(42);
1320 .execSQL("CREATE TABLE t3(a VARCHAR(100))");
1321 mDatabase.execSQL("CREATE INDEX i3a ON t3(a)");
1323 for (int i = 0; i < SIZE; i++) {
1324 int r = random.nextInt(100000);
1325 mDatabase.execSQL("INSERT INTO t3 VALUES('"
1326 + numberName(r) + "')");
1329 for (int i = 0; i < SIZE; i++) {
1330 where[i] = "a LIKE '*e*'";
1338 for (int i = 0; i < SIZE; i++) {
1339 mDatabase.query("t3", COLUMNS, where[i], null, null, null, null);
1344 public static final String[] ONES =
1345 {"zero", "one", "two", "three", "four", "five", "six", "seven",
1346 "eight", "nine", "ten", "eleven", "twelve", "thirteen",
1347 "fourteen", "fifteen", "sixteen", "seventeen", "eighteen",
1350 public static final String[] TENS =
1351 {"", "ten", "twenty", "thirty", "forty", "fifty", "sixty",
1352 "seventy", "eighty", "ninety"};