[Groonga-commit] groonga/grnxx at 63461a8 [master] Gnx: add GrnColumn.GetValues() for benchmark.

Back to archive index

susumu.yata null+****@clear*****
Fri May 8 17:37:00 JST 2015


susumu.yata	2015-05-08 17:37:00 +0900 (Fri, 08 May 2015)

  New Revision: 63461a8de671aa4bfe3e144baf42a7c58d49183c
  https://github.com/groonga/grnxx/commit/63461a8de671aa4bfe3e144baf42a7c58d49183c

  Message:
    Gnx: add GrnColumn.GetValues() for benchmark.

  Modified files:
    go3/gnx/grn.go
    go3/gnx/grn_cgo.c
    go3/gnx/grn_cgo.h
    go3/gnx/grn_test.go

  Modified: go3/gnx/grn.go (+47 -0)
===================================================================
--- go3/gnx/grn.go    2015-05-08 11:20:57 +0900 (b412769)
+++ go3/gnx/grn.go    2015-05-08 17:37:00 +0900 (9b93901)
@@ -1165,3 +1165,50 @@ func (column *GrnColumn) GetValue(id Int) (interface{}, error) {
 	}
 	return nil, fmt.Errorf("undefined value type: valueType = %d", column.valueType)
 }
+
+func (column *GrnColumn) getBools(ids []Int) (interface{}, error) {
+	grnValues := make([]C.grn_bool, len(ids))
+	if ok := C.grn_cgo_column_get_bools(column.table.db.ctx, column.obj,
+		C.size_t(len(ids)), (*C.int64_t)(unsafe.Pointer(&ids[0])),
+		&grnValues[0]); ok != C.GRN_TRUE {
+		return nil, fmt.Errorf("grn_cgo_column_get_bools() failed")
+	}
+	values := make([]Bool, len(ids))
+	for i, _ := range values {
+		if grnValues[i] == C.GRN_TRUE {
+			values[i] = True
+		}
+	}
+	return values, nil
+}
+
+func (column *GrnColumn) GetValues(ids []Int) (interface{}, error) {
+	if !column.isVector {
+		switch column.valueType {
+		case BoolID:
+			return column.getBools(ids)
+//		case IntID:
+//			return column.getInts(ids)
+//		case FloatID:
+//			return column.getFloats(ids)
+//		case GeoPointID:
+//			return column.getGeoPoints(ids)
+//		case TextID:
+//			return column.getTexts(ids)
+		}
+	} else {
+//		switch column.valueType {
+//		case BoolID:
+//			return column.getBoolVectors(ids)
+//		case IntID:
+//			return column.getIntVectors(ids)
+//		case FloatID:
+//			return column.getFloatVectors(ids)
+//		case GeoPointID:
+//			return column.getGeoPointVectors(ids)
+//		case TextID:
+//			return column.getTextVectors(ids)
+//		}
+	}
+	return nil, fmt.Errorf("undefined value type: valueType = %d", column.valueType)
+}

  Modified: go3/gnx/grn_cgo.c (+13 -0)
===================================================================
--- go3/gnx/grn_cgo.c    2015-05-08 11:20:57 +0900 (e488cbd)
+++ go3/gnx/grn_cgo.c    2015-05-08 17:37:00 +0900 (75b1610)
@@ -467,3 +467,16 @@ grn_bool grn_cgo_column_get_text_vector(grn_ctx *ctx, grn_obj *column,
   GRN_OBJ_FIN(ctx, &value_obj);
   return GRN_TRUE;
 }
+
+grn_bool grn_cgo_column_get_bools(grn_ctx *ctx, grn_obj *column, size_t n,
+                                  const int64_t *ids, grn_bool *values) {
+  grn_obj value_obj;
+  GRN_BOOL_INIT(&value_obj, 0);
+  size_t i;
+  for (i = 0; i < n; i++) {
+    grn_obj_get_value(ctx, column, (grn_id)ids[i], &value_obj);
+    values[i] = GRN_BOOL_VALUE(&value_obj);
+  }
+  GRN_OBJ_FIN(ctx, &value_obj);
+  return GRN_TRUE;
+}

  Modified: go3/gnx/grn_cgo.h (+3 -0)
===================================================================
--- go3/gnx/grn_cgo.h    2015-05-08 11:20:57 +0900 (9fcc334)
+++ go3/gnx/grn_cgo.h    2015-05-08 17:37:00 +0900 (53bb968)
@@ -142,4 +142,7 @@ grn_bool grn_cgo_column_get_geo_point_vector(grn_ctx *ctx, grn_obj *column,
 grn_bool grn_cgo_column_get_text_vector(grn_ctx *ctx, grn_obj *column,
                                         grn_id id, grn_cgo_vector *value);
 
+grn_bool grn_cgo_column_get_bools(grn_ctx *ctx, grn_obj *column, size_t n,
+                                  const int64_t *ids, grn_bool *values);
+
 #endif  // GRN_CGO_H

  Modified: go3/gnx/grn_test.go (+33 -1)
===================================================================
--- go3/gnx/grn_test.go    2015-05-08 11:20:57 +0900 (82ac466)
+++ go3/gnx/grn_test.go    2015-05-08 17:37:00 +0900 (b60e492)
@@ -948,10 +948,13 @@ func benchmarkGrnDBSelectForVector(b *testing.B, valueType string) {
 
 	b.ResetTimer()
 	for i := 0; i < b.N; i++ {
-		_, err := db.Query("select Table --output_columns Value --limit -1")
+		bytes, err := db.Query("select Table --output_columns Value --limit -1")
 		if err != nil {
 			b.Fatalf("DB.Query() failed: %s", err)
 		}
+		if len(bytes) < numTestRows * 5 {
+			b.Fatalf("DB.Query() failed: %s", err)
+		}
 	}
 }
 
@@ -994,3 +997,32 @@ func BenchmarkGrnDBSelectForGeoPointVector(b *testing.B) {
 func BenchmarkGrnDBSelectForTextVector(b *testing.B) {
 	benchmarkGrnDBSelectForVector(b, "Text")
 }
+
+func benchmarkGrnColumnGetValuesForScalar(b *testing.B, valueType string) {
+	dirPath, _, db, table, column :=
+		createTempGrnColumn(b, "Table", nil, "Value", valueType, nil)
+	defer removeTempGrnDB(b, dirPath, db)
+	ids := make([]Int, numTestRows)
+	for i, _ := range ids {
+		_, id, err := table.InsertRow(nil)
+		if err != nil {
+			b.Fatalf("Table.InsertRow() failed: %s", err)
+		}
+		if err := column.SetValue(id, generateRandomValue(valueType)); err != nil {
+			b.Fatalf("Column.SetValue() failed: %s", err)
+		}
+		ids[i] = id
+	}
+
+	b.ResetTimer()
+	for i := 0; i < b.N; i++ {
+		if _, err := column.GetValues(ids); err != nil {
+			b.Fatalf("Column.GetValues() failed: %s", err)
+		}
+	}
+}
+
+
+func BenchmarkGrnColumnGetValuesForBool(b *testing.B) {
+	benchmarkGrnColumnGetValuesForScalar(b, "Bool")
+}
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index