[GRASS-SVN] r51097 - sandbox/martinl/v.test
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Mar 17 16:47:28 EDT 2012
Author: martinl
Date: 2012-03-17 13:47:28 -0700 (Sat, 17 Mar 2012)
New Revision: 51097
Modified:
sandbox/martinl/v.test/main.c
sandbox/martinl/v.test/v.test.html
Log:
v.test: various updates, fix timevaldiff
Modified: sandbox/martinl/v.test/main.c
===================================================================
--- sandbox/martinl/v.test/main.c 2012-03-17 20:45:31 UTC (rev 51096)
+++ sandbox/martinl/v.test/main.c 2012-03-17 20:47:28 UTC (rev 51097)
@@ -21,19 +21,32 @@
#include <grass/vector.h>
#include <grass/glocale.h>
+#define SEP "----------------------------------------------------------------------------\n"
+
+static long timevaldiff(struct timeval *starttime, struct timeval *finishtime)
+{
+ long msec;
+
+ msec = (finishtime->tv_sec - starttime->tv_sec) * 1000;
+ msec += (finishtime->tv_usec - starttime->tv_usec) / 1000;
+
+ return msec;
+}
+
int main(int argc, char *argv[])
{
struct GModule *module;
struct Map_info Map;
struct {
- struct Option *input, *num, *type, *field;
+ struct Option *input, *num, *type, *field, *id;
} opt;
struct {
struct Flag *s, *r, *l;
} flag;
- int i, line, number, npoints, nlines, ltype;
- double diff, sdiff;
+ int i, line, number;
+ int npoints, nlines, nboundaries, ncentroids, ltype;
+ long diff, sdiff;
struct line_pnts *Points;
struct line_cats *Cats;
@@ -51,15 +64,21 @@
opt.input = G_define_standard_option(G_OPT_V_MAP);
opt.field = G_define_standard_option(G_OPT_V_FIELD);
+ opt.field->answer = "-1";
opt.type = G_define_standard_option(G_OPT_V_TYPE);
opt.type->answer = "";
+ opt.id = G_define_option();
+ opt.id->key = "id";
+ opt.id->type = TYPE_INTEGER;
+ opt.id->description = _("Feature id for random access");
+
opt.num = G_define_option();
opt.num->key = "n";
opt.num->description = _("Number of tests");
opt.num->type = TYPE_INTEGER;
- opt.num->answer = "100";
+ opt.num->answer = "10";
flag.s = G_define_flag();
flag.s->key = 's';
@@ -106,14 +125,14 @@
window.top, window.bottom);
}
- npoints = nlines = sdiff = 0;
+ sdiff = 0;
if (flag.s->answer) {
for (i = 0; i < number; i++) {
struct timeval start_time, end_time;
G_percent(i, number, 5);
-
- line = 0;
+
+ npoints = nlines = nboundaries = ncentroids = line = 0;
Vect_rewind(&Map);
gettimeofday(&start_time, NULL);
@@ -121,67 +140,111 @@
ltype = Vect_read_next_line(&Map, Points, Cats);
if (ltype < 0)
break;
- if (ltype == GV_POINT)
+ switch(ltype) {
+ case GV_POINT:
npoints++;
- else if (ltype == GV_LINE)
+ break;
+ case GV_LINE:
nlines++;
+ break;
+ case GV_CENTROID:
+ ncentroids++;
+ break;
+ case GV_BOUNDARY:
+ nboundaries++;
+ break;
+ }
line++;
}
gettimeofday(&end_time, NULL);
- diff = (double) end_time.tv_usec - start_time.tv_usec;
- if (diff > 0)
- sdiff += end_time.tv_usec - start_time.tv_usec;
- else
- G_debug(1, "%f", diff); /* ??? */
+ diff = timevaldiff(&start_time, &end_time);
+ G_verbose_message(_("Pass %d: diff = %ld msec"), i, diff);
+ sdiff += diff;
}
}
else {
- int nlines;
+ int nfeatures;
if (flag.l->answer)
G_fatal_error(_("Random access requires vector map "
"open on topological level"));
- nlines = Vect_get_num_lines(&Map);
+ nfeatures = Vect_get_num_lines(&Map);
for (i = 0; i < number; i++) {
struct timeval start_time, end_time;
G_percent(i, number, 5);
+ npoints = nlines = nboundaries = ncentroids = 0;
gettimeofday(&start_time, NULL);
- for (line = 1; line < nlines; line++) {
+ if (opt.id->answer) {
+ line = atoi(opt.id->answer);
ltype = Vect_read_line(&Map, Points, Cats, line);
- if (ltype == GV_POINT)
+ switch(ltype) {
+ case GV_POINT:
npoints++;
- else if (ltype == GV_LINE)
+ break;
+ case GV_LINE:
nlines++;
-
+ break;
+ case GV_CENTROID:
+ ncentroids++;
+ break;
+ case GV_BOUNDARY:
+ nboundaries++;
+ break;
+ }
}
+ else {
+ for (line = 1; line <= nfeatures; line++) {
+ ltype = Vect_read_line(&Map, Points, Cats, line);
+ switch(ltype) {
+ case GV_POINT:
+ npoints++;
+ break;
+ case GV_LINE:
+ nlines++;
+ break;
+ case GV_CENTROID:
+ ncentroids++;
+ break;
+ case GV_BOUNDARY:
+ nboundaries++;
+ break;
+ }
+ }
+ }
gettimeofday(&end_time, NULL);
- diff = (double) end_time.tv_usec - start_time.tv_usec;
- if (diff > 0)
- sdiff += end_time.tv_usec - start_time.tv_usec;
- else
- G_debug(1, "%f", diff); /* ??? */
+ diff = timevaldiff(&start_time, &end_time);
+ G_verbose_message(_("Pass %d: diff = %ld msec"), i, diff);
+ sdiff += diff;
}
}
if (npoints > 0)
- fprintf(stdout, "npoints=");
+ fprintf(stdout, "npoints=%d\t", npoints);
if (nlines > 0)
- fprintf(stdout, "nlines=");
- if (npoints > 0 || nlines > 0) {
- fprintf(stdout, "%d\t%.6f\t(%s)\n", line, (sdiff / number) / 1e6,
+ fprintf(stdout, "nlines=%d\t", nlines);
+ if (ncentroids > 0)
+ fprintf(stdout, "ncentroids=%d\t", ncentroids);
+ if (nboundaries > 0)
+ fprintf(stdout, "nboundaries=%d\t", nboundaries);
+
+ fprintf(stdout, "\n");
+ fprintf(stdout, SEP);
+ if (npoints + nlines + ncentroids + nboundaries > 0) {
+ fprintf(stdout, "%10d msec\t(%s)\n", (int) (sdiff / number),
Vect_maptype_info(&Map));
}
else {
G_message(_("No feature read"));
}
+ fprintf(stdout, SEP);
Vect_close(&Map);
-
+
return (EXIT_SUCCESS);
}
Modified: sandbox/martinl/v.test/v.test.html
===================================================================
--- sandbox/martinl/v.test/v.test.html 2012-03-17 20:45:31 UTC (rev 51096)
+++ sandbox/martinl/v.test/v.test.html 2012-03-17 20:47:28 UTC (rev 51097)
@@ -38,20 +38,15 @@
v.test -sr map=$MAP
</pre></div>
-Testing random access:
+Testing random access (note constraints by region, layer or type are
+ignored):
<div class="code"><pre>
-# random access on topological level
+# random access on topological level (in loop)
v.test map=$MAP
-# random access on topological level with type constraint
-v.test map=$MAP type=line
-
-# random access on topological level with layer constraint
-v.test map=$MAP layer=2
-
-# random access on topological level with region constraint
-v.test -r map=$MAP
+# random access on topological level (selected feature only)
+v.test map=$MAP id=1
</pre></div>
<h2>AUTHOR</h2>
More information about the grass-commit
mailing list