aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/tests/attribute/benchmark/attributebenchmark.cpp
blob: 4ca01baacea98ea0d885830263180a790b876e2c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include <vespa/searchlib/util/randomgenerator.h>
#include <vespa/searchlib/attribute/attribute.h>
#include <vespa/searchlib/attribute/attributeguard.h>
#include <vespa/searchlib/attribute/attributefactory.h>
#include <vespa/searchcommon/attribute/config.h>
#include <thread>
#include <vespa/vespalib/util/signalhandler.h>
#include <iostream>
#include "attributesearcher.h"
#include "attributeupdater.h"
#include <sys/resource.h>
#include <unistd.h>

#include <vespa/log/log.h>
LOG_SETUP("attributebenchmark");

using std::shared_ptr;

using NumVector = std::vector<uint32_t>;
using StringVector = std::vector<vespalib::string>;
using AttrConfig = search::attribute::Config;
using search::attribute::BasicType;
using search::attribute::CollectionType;

namespace search {

using AttributePtr = AttributeVector::SP;
using DocId = AttributeVector::DocId;

class AttributeBenchmark
{
private:
    class Config {
    public:
        vespalib::string _attribute;
        uint32_t _numDocs;
        uint32_t _numUpdates;
        uint32_t _numValues;
        uint32_t _numSearchers;
        uint32_t _numQueries;
        bool _searchersOnly;
        bool _validate;
        uint32_t _populateRuns;
        uint32_t _updateRuns;
        uint32_t _commitFreq;
        uint32_t _minValueCount;
        uint32_t _maxValueCount;
        uint32_t _minStringLen;
        uint32_t _maxStringLen;
        uint32_t _seed;
        bool _writeAttribute;
        int64_t _rangeStart;
        int64_t _rangeEnd;
        int64_t _rangeDelta;
        bool _rangeSearch;
        uint32_t _prefixLength;
        bool _prefixSearch;


        Config() : _attribute(""), _numDocs(0), _numUpdates(0), _numValues(0),
        _numSearchers(0), _numQueries(0), _searchersOnly(true), _validate(false), _populateRuns(0), _updateRuns(0),
        _commitFreq(0), _minValueCount(0), _maxValueCount(0), _minStringLen(0), _maxStringLen(0), _seed(0),
        _writeAttribute(false), _rangeStart(0), _rangeEnd(0), _rangeDelta(0), _rangeSearch(false),
        _prefixLength(0), _prefixSearch(false) {}
        void printXML() const;
    };

    class Resource {
    private:
        std::vector<struct rusage> _usages;
        struct rusage _reset;

    public:
        Resource() : _usages(), _reset() { reset(); };
        void reset() {
            getrusage(0, &_reset);
        }
        void saveUsage() {
            struct rusage now;
            getrusage(0, &now);
            struct rusage usage = computeDifference(_reset, now);
            _usages.push_back(usage);
        }
        void printLastXML(uint32_t opCount) {
            (void) opCount;
            struct rusage & usage = _usages.back();
            std::cout << "<ru_utime>" << usage.ru_utime.tv_sec * 1000 + usage.ru_utime.tv_usec / 1000
                << "</ru_utime>" << std::endl;
            std::cout << "<ru_stime>" << usage.ru_stime.tv_sec * 1000 + usage.ru_stime.tv_usec / 1000
                << "</ru_stime>" << std::endl;
            std::cout << "<ru_nvcsw>" << usage.ru_nvcsw << "</ru_nvcsw>" << std::endl;
            std::cout << "<ru_nivcsw>" << usage.ru_nivcsw << "</ru_nivcsw>" << std::endl;
        }
        static struct rusage computeDifference(struct rusage & first, struct rusage & second);
    };

    Config _config;
    RandomGenerator _rndGen;

    void init(const Config & config);
    void usage();

    // benchmark helper methods
    void addDocs(const AttributePtr & ptr, uint32_t numDocs);
    template <typename Vector, typename T, typename BT>
    void benchmarkPopulate(const AttributePtr & ptr, const std::vector<T> & values, uint32_t id);
    template <typename Vector, typename T, typename BT>
    void benchmarkUpdate(const AttributePtr & ptr, const std::vector<T> & values, uint32_t id);

    template <typename T>
    std::vector<vespalib::string> prepareForPrefixSearch(const std::vector<T> & values) const;
    template <typename T>
    void benchmarkSearch(const AttributePtr & ptr, const std::vector<T> & values);
    template <typename Vector, typename T, typename BT>
    void benchmarkSearchWithUpdater(const AttributePtr & ptr,
                                    const std::vector<T> & values);

    template <typename Vector, typename T, typename BT>
    void benchmarkAttribute(const AttributePtr & ptr, const std::vector<T> & values);

    // Numeric Attribute
    void benchmarkNumeric(const AttributePtr & ptr);

    // String Attribute
    void benchmarkString(const AttributePtr & ptr);


public:
    AttributeBenchmark() : _config(), _rndGen() {}
    ~AttributeBenchmark() = default;
    int main(int argc, char **argv);
};


void
AttributeBenchmark::Config::printXML() const
{
    std::cout << "<config>" << std::endl;
    std::cout << "<attribute>" << _attribute << "</attribute>" << std::endl;
    std::cout << "<num-docs>" << _numDocs << "</num-docs>" << std::endl;
    std::cout << "<num-updates>" << _numUpdates << "</num-updates>" << std::endl;
    std::cout << "<num-values>" << _numValues << "</num-values>" << std::endl;
    std::cout << "<num-searchers>" << _numSearchers << "</num-searchers>" << std::endl;
    std::cout << "<num-queries>" << _numQueries << "</num-queries>" << std::endl;
    std::cout << "<searchers-only>" << (_searchersOnly ? "true" : "false") << "</searchers-only>" << std::endl;
    std::cout << "<validate>" << (_validate ? "true" : "false") << "</validate>" << std::endl;
    std::cout << "<populate-runs>" << _populateRuns << "</populate-runs>" << std::endl;
    std::cout << "<update-runs>" << _updateRuns << "</update-runs>" << std::endl;
    std::cout << "<commit-freq>" << _commitFreq << "</commit-freq>" << std::endl;
    std::cout << "<min-value-count>" << _minValueCount << "</min-value-count>" << std::endl;
    std::cout << "<max-value-count>" << _maxValueCount << "</max-value-count>" << std::endl;
    std::cout << "<min-string-len>" << _minStringLen << "</min-string-len>" << std::endl;
    std::cout << "<max-string-len>" << _maxStringLen << "</max-string-len>" << std::endl;
    std::cout << "<seed>" << _seed << "</seed>" << std::endl;
    std::cout << "<range-start>" << _rangeStart << "</range-start>" << std::endl;
    std::cout << "<range-end>" << _rangeEnd << "</range-end>" << std::endl;
    std::cout << "<range-delta>" << _rangeDelta << "</range-delta>" << std::endl;
    std::cout << "<range-search>" << (_rangeSearch ? "true" : "false") << "</range-search>" << std::endl;
    std::cout << "<prefix-length>" << _prefixLength << "</range-length>" << std::endl;
    std::cout << "<prefix-search>" << (_prefixSearch ? "true" : "false") << "</prefix-search>" << std::endl;
    std::cout << "</config>" << std::endl;
}

void
AttributeBenchmark::init(const Config & config)
{
    _config = config;
    _rndGen.srand(_config._seed);
}


//-----------------------------------------------------------------------------
// Benchmark helper methods
//-----------------------------------------------------------------------------
void
AttributeBenchmark::addDocs(const AttributePtr & ptr, uint32_t numDocs)
{
    DocId startDoc;
    DocId lastDoc;
    bool success = ptr->addDocs(startDoc, lastDoc, numDocs);
    assert(success);
    (void) success;
    assert(startDoc == 0);
    assert(lastDoc + 1 == numDocs);
    assert(ptr->getNumDocs() == numDocs);
}

template <typename Vector, typename T, typename BT>
void
AttributeBenchmark::benchmarkPopulate(const AttributePtr & ptr, const std::vector<T> & values, uint32_t id)
{
    std::cout << "<!-- Populate " << _config._numDocs << " documents -->" << std::endl;
    AttributeUpdater<Vector, T, BT>
        updater(ptr, values, _rndGen, _config._validate, _config._commitFreq,
                _config._minValueCount, _config._maxValueCount);
    updater.populate();
    std::cout << "<populate id='" << id << "'>" << std::endl;
    updater.getStatus().printXML();
    std::cout << "</populate>" << std::endl;
    if (_config._validate) {
        std::cout << "<!-- All " << updater.getValidator().getTotalCnt()
            << " asserts passed -->" << std::endl;
    }
}

template <typename Vector, typename T, typename BT>
void
AttributeBenchmark::benchmarkUpdate(const AttributePtr & ptr, const std::vector<T> & values, uint32_t id)
{
    std::cout << "<!-- Apply " << _config._numUpdates << " updates -->" << std::endl;
    AttributeUpdater<Vector, T, BT>
        updater(ptr, values, _rndGen, _config._validate, _config._commitFreq,
                _config._minValueCount, _config._maxValueCount);
    updater.update(_config._numUpdates);
    std::cout << "<update id='" << id << "'>" << std::endl;
    updater.getStatus().printXML();
    std::cout << "</update>" << std::endl;
    if (_config._validate) {
        std::cout << "<!-- All " << updater.getValidator().getTotalCnt()
            << " asserts passed -->" << std::endl;
    }
}

template <typename T>
std::vector<vespalib::string>
AttributeBenchmark::prepareForPrefixSearch(const std::vector<T> & values) const
{
    (void) values;
    return std::vector<vespalib::string>();
}

template <>
std::vector<vespalib::string>
AttributeBenchmark::prepareForPrefixSearch(const std::vector<AttributeVector::WeightedString> & values) const
{
    std::vector<vespalib::string> retval;
    retval.reserve(values.size());
    for (size_t i = 0; i < values.size(); ++i) {
        retval.push_back(values[i].getValue().substr(0, _config._prefixLength));
    }
    return retval;
}

template <typename T>
void
AttributeBenchmark::benchmarkSearch(const AttributePtr & ptr, const std::vector<T> & values)
{
    std::vector<AttributeSearcher *> searchers;
    if (_config._numSearchers > 0) {
        std::cout << "<!-- Starting " << _config._numSearchers << " searcher threads with "
            << _config._numQueries << " queries each -->" << std::endl;

        std::vector<vespalib::string> prefixStrings = prepareForPrefixSearch(values);

        for (uint32_t i = 0; i < _config._numSearchers; ++i) {
            if (_config._rangeSearch) {
                RangeSpec spec(_config._rangeStart, _config._rangeEnd, _config._rangeDelta);
                searchers.push_back(new AttributeRangeSearcher(ptr, spec, _config._numQueries));
            } else if (_config._prefixSearch) {
                searchers.push_back(new AttributePrefixSearcher(ptr, prefixStrings, _config._numQueries));
            } else {
                searchers.push_back(new AttributeFindSearcher<T>(ptr, values, _config._numQueries));
            }
            searchers.back()->start();
        }

        for (uint32_t i = 0; i < searchers.size(); ++i) {
            searchers[i]->join();
        }

        AttributeSearcherStatus totalStatus;
        for (uint32_t i = 0; i < searchers.size(); ++i) {
            std::cout << "<searcher-summary id='" << i << "'>" << std::endl;
            searchers[i]->getStatus().printXML();
            std::cout << "</searcher-summary>" << std::endl;
            totalStatus.merge(searchers[i]->getStatus());
            delete searchers[i];
        }
        std::cout << "<total-searcher-summary>" << std::endl;
        totalStatus.printXML();
        std::cout << "</total-searcher-summary>" << std::endl;
    }
}

template <typename Vector, typename T, typename BT>
void
AttributeBenchmark::benchmarkSearchWithUpdater(const AttributePtr & ptr,
                                               const std::vector<T> & values)
{
    if (_config._numSearchers > 0) {
        std::cout << "<!-- Starting 1 updater thread -->" << std::endl;
        AttributeUpdaterThread<Vector, T, BT>
            updater(ptr, values, _rndGen, _config._validate, _config._commitFreq,
                    _config._minValueCount, _config._maxValueCount);
        updater.start();
        benchmarkSearch(ptr, values);
        updater.stop();
        updater.join();
        std::cout << "<updater-summary>" << std::endl;
        updater.getStatus().printXML();
        std::cout << "</updater-summary>" << std::endl;
        if (_config._validate) {
            std::cout << "<!-- All " << updater.getValidator().getTotalCnt()
                << " asserts passed -->" << std::endl;
        }
    }
}

template <typename Vector, typename T, typename BT>
void
AttributeBenchmark::benchmarkAttribute(const AttributePtr & ptr, const std::vector<T> & values)
{
    addDocs(ptr, _config._numDocs);

    // populate
    for (uint32_t i = 0; i < _config._populateRuns; ++i) {
        benchmarkPopulate<Vector, T, BT>(ptr, values, i);
    }

    // update
    if (_config._numUpdates > 0) {
        for (uint32_t i = 0; i < _config._updateRuns; ++i) {
            benchmarkUpdate<Vector, T, BT>(ptr, values, i);
        }
    }

    // search
    if (_config._searchersOnly) {
        benchmarkSearch(ptr, values);
    } else {
        benchmarkSearchWithUpdater<Vector, T, BT>(ptr, values);
    }
}


//-----------------------------------------------------------------------------
// Numeric Attribute
//-----------------------------------------------------------------------------
void
AttributeBenchmark::benchmarkNumeric(const AttributePtr & ptr)
{
    NumVector values;
    if (_config._rangeSearch) {
        values.reserve(_config._numValues);
        for (uint32_t i = 0; i < _config._numValues; ++i) {
            values.push_back(i);
        }
    } else {
        _rndGen.fillRandomIntegers(values, _config._numValues);
    }

    std::vector<int32_t> weights;
    _rndGen.fillRandomIntegers(weights, _config._numValues);

    std::vector<AttributeVector::WeightedInt> weightedVector;
    weightedVector.reserve(values.size());
    for (size_t i = 0; i < values.size(); ++i) {
        if (!ptr->hasWeightedSetType()) {
            weightedVector.push_back(AttributeVector::WeightedInt(values[i]));
        } else {
            weightedVector.push_back(AttributeVector::WeightedInt(values[i], weights[i]));
        }
    }
    benchmarkAttribute<IntegerAttribute, AttributeVector::WeightedInt, AttributeVector::WeightedInt>
        (ptr, weightedVector);
}


//-----------------------------------------------------------------------------
// String Attribute
//-----------------------------------------------------------------------------
void
AttributeBenchmark::benchmarkString(const AttributePtr & ptr)
{
    StringVector strings;
    _rndGen.fillRandomStrings(strings, _config._numValues, _config._minStringLen, _config._maxStringLen);

    std::vector<int32_t> weights;
    _rndGen.fillRandomIntegers(weights, _config._numValues);

    std::vector<AttributeVector::WeightedString> weightedVector;
    weightedVector.reserve(strings.size());
    for (size_t i = 0; i < strings.size(); ++i) {
        if (!ptr->hasWeightedSetType()) {
            weightedVector.push_back(AttributeVector::WeightedString(strings[i]));
        } else {
            weightedVector.push_back(AttributeVector::WeightedString(strings[i], weights[i]));
        }
    }
    benchmarkAttribute<StringAttribute, AttributeVector::WeightedString, AttributeVector::WeightedString>
        (ptr, weightedVector);
}


//-----------------------------------------------------------------------------
// Resource utilization
//-----------------------------------------------------------------------------
struct rusage
AttributeBenchmark::Resource::computeDifference(struct rusage & first, struct rusage & second)
{
    struct rusage result;
    // utime
    uint64_t firstutime = first.ru_utime.tv_sec * 1000000 + first.ru_utime.tv_usec;
    uint64_t secondutime = second.ru_utime.tv_sec * 1000000 + second.ru_utime.tv_usec;
    uint64_t resultutime = secondutime - firstutime;
    result.ru_utime.tv_sec = resultutime / 1000000;
    result.ru_utime.tv_usec = resultutime % 1000000;

    // stime
    uint64_t firststime = first.ru_stime.tv_sec * 1000000 + first.ru_stime.tv_usec;
    uint64_t secondstime = second.ru_stime.tv_sec * 1000000 + second.ru_stime.tv_usec;
    uint64_t resultstime = secondstime - firststime;
    result.ru_stime.tv_sec = resultstime / 1000000;
    result.ru_stime.tv_usec = resultstime % 1000000;

    result.ru_maxrss = second.ru_maxrss; // - first.ru_maxrss;
    result.ru_ixrss = second.ru_ixrss; // - first.ru_ixrss;
    result.ru_idrss = second.ru_idrss; // - first.ru_idrss;
    result.ru_isrss = second.ru_isrss; // - first.ru_isrss;
    result.ru_minflt = second.ru_minflt - first.ru_minflt;
    result.ru_majflt = second.ru_majflt - first.ru_majflt;
    result.ru_nswap = second.ru_nswap - first.ru_nswap;
    result.ru_inblock = second.ru_inblock - first.ru_inblock;
    result.ru_oublock = second.ru_oublock - first.ru_oublock;
    result.ru_msgsnd = second.ru_msgsnd - first.ru_msgsnd;
    result.ru_msgrcv = second.ru_msgrcv - first.ru_msgrcv;
    result.ru_nsignals = second.ru_nsignals - first.ru_nsignals;
    result.ru_nvcsw = second.ru_nvcsw - first.ru_nvcsw;
    result.ru_nivcsw = second.ru_nivcsw - first.ru_nivcsw;

    return result;
}


void
AttributeBenchmark::usage()
{
    std::cout << "usage: attributebenchmark [-n numDocs] [-u numUpdates] [-v numValues]" << std::endl;
    std::cout << "                          [-s numSearchers] [-q numQueries] [-p populateRuns] [-r updateRuns]" << std::endl;
    std::cout << "                          [-c commitFrequency] [-l minValueCount] [-h maxValueCount]" << std::endl;
    std::cout << "                          [-i minStringLen] [-a maxStringLen] [-e seed]" << std::endl;
    std::cout << "                          [-S rangeStart] [-E rangeEnd] [-D rangeDelta] [-L prefixLength]" << std::endl;
    std::cout << "                          [-b (searchers with updater)] [-R (range search)] [-P (prefix search)]" << std::endl;
    std::cout << "                          [-t (validate updates)] [-w (write attribute to disk)]" << std::endl;
    std::cout << "                          <attribute>" << std::endl;
    std::cout << " <attribute> : s-uint32, a-uint32, ws-uint32" << std::endl;
    std::cout << "               s-fa-uint32, a-fa-uint32, ws-fa-uint32" << std::endl;
    std::cout << "               s-fs-uint32, a-fs-uint32, ws-fs-uint32 ws-frs-uint32" << std::endl;
    std::cout << "               s-string, a-string, ws-string" << std::endl;
    std::cout << "               s-fs-string, a-fs-string, ws-fs-string ws-frs-string" << std::endl;
}

int
AttributeBenchmark::main(int argc, char **argv)
{
    Config dc;
    dc._numDocs = 50000;
    dc._numUpdates = 50000;
    dc._numValues = 1000;
    dc._numSearchers = 0;
    dc._numQueries = 1000;
    dc._searchersOnly = true;
    dc._validate = false;
    dc._populateRuns = 1;
    dc._updateRuns = 1;
    dc._commitFreq = 1000;
    dc._minValueCount = 0;
    dc._maxValueCount = 20;
    dc._minStringLen = 1;
    dc._maxStringLen = 50;
    dc._seed = 555;
    dc._writeAttribute = false;
    dc._rangeStart = 0;
    dc._rangeEnd = 1000;
    dc._rangeDelta = 10;
    dc._rangeSearch = false;
    dc._prefixLength = 2;
    dc._prefixSearch = false;

    int opt;
    bool optError = false;
    while ((opt = getopt(argc, argv, "n:u:v:s:q:p:r:c:l:h:i:a:e:S:E:D:L:bRPtw")) != -1) {
        switch (opt) {
        case 'n':
            dc._numDocs = atoi(optarg);
            break;
        case 'u':
            dc._numUpdates = atoi(optarg);
            break;
        case 'v':
            dc._numValues = atoi(optarg);
            break;
        case 's':
            dc._numSearchers = atoi(optarg);
            break;
        case 'q':
            dc._numQueries = atoi(optarg);
            break;
        case 'p':
            dc._populateRuns = atoi(optarg);
            break;
        case 'r':
            dc._updateRuns = atoi(optarg);
            break;
        case 'c':
            dc._commitFreq = atoi(optarg);
            break;
        case 'l':
            dc._minValueCount = atoi(optarg);
            break;
        case 'h':
            dc._maxValueCount = atoi(optarg);
            break;
        case 'i':
            dc._minStringLen = atoi(optarg);
            break;
        case 'a':
            dc._maxStringLen = atoi(optarg);
            break;
        case 'e':
            dc._seed = atoi(optarg);
            break;
        case 'S':
            dc._rangeStart = strtoll(optarg, NULL, 10);
            break;
        case 'E':
            dc._rangeEnd = strtoll(optarg, NULL, 10);
            break;
        case 'D':
            dc._rangeDelta = strtoll(optarg, NULL, 10);
            break;
        case 'L':
            dc._prefixLength = atoi(optarg);
            break;
        case 'b':
            dc._searchersOnly = false;
            break;
        case 'R':
            dc._rangeSearch = true;
            break;
        case 'P':
            dc._prefixSearch = true;
            break;
        case 't':
            dc._validate = true;
            break;
        case 'w':
            dc._writeAttribute = true;
            break;
        default:
            optError = true;
            break;
        }
    }

    if (argc != (optind + 1) || optError) {
        usage();
        return -1;
    }

    dc._attribute = vespalib::string(argv[optind]);

    std::cout << "<attribute-benchmark>" << std::endl;
    init(dc);
    _config.printXML();

    AttributePtr ptr;

    if (_config._attribute == "s-int32") {
        std::cout << "<!-- Benchmark SingleValueNumericAttribute<int32_t> -->" << std::endl;
        ptr = AttributeFactory::createAttribute("s-int32", AttrConfig(BasicType::INT32, CollectionType::SINGLE));
        benchmarkNumeric(ptr);

    } else if (_config._attribute == "a-int32") {
        std::cout << "<!-- Benchmark MultiValueNumericAttribute<int32_t> (array) -->" << std::endl;
        ptr = AttributeFactory::createAttribute("a-int32", AttrConfig(BasicType::INT32, CollectionType::ARRAY));
        benchmarkNumeric(ptr);

    } else if (_config._attribute == "ws-int32") {
        std::cout << "<!-- Benchmark MultiValueNumericAttribute<int32_t> (wset) -->" << std::endl;
        ptr = AttributeFactory::createAttribute("ws-int32", AttrConfig(BasicType::INT32, CollectionType::WSET));
        benchmarkNumeric(ptr);

    } else if (_config._attribute == "s-fs-int32") {
        std::cout << "<!-- Benchmark SingleValueNumericPostingAttribute<int32_t> -->" << std::endl;
        AttrConfig cfg(BasicType::INT32, CollectionType::SINGLE);
        cfg.setFastSearch(true);
        ptr = AttributeFactory::createAttribute("s-fs-int32", cfg);
        benchmarkNumeric(ptr);

    } else if (_config._attribute == "a-fs-int32") {
        std::cout << "<!-- Benchmark MultiValueNumericPostingAttribute<int32_t> (array) -->" << std::endl;
        AttrConfig cfg(BasicType::INT32, CollectionType::ARRAY);
        cfg.setFastSearch(true);
        ptr = AttributeFactory::createAttribute("a-fs-int32", cfg);
        benchmarkNumeric(ptr);

    } else if (_config._attribute == "ws-fs-int32") {
        std::cout << "<!-- Benchmark MultiValueNumericPostingAttribute<int32_t> (wset) -->" << std::endl;
        AttrConfig cfg(BasicType::INT32, CollectionType::WSET);
        cfg.setFastSearch(true);
        ptr = AttributeFactory::createAttribute("ws-fs-int32", cfg);
        benchmarkNumeric(ptr);

    } else if (_config._attribute == "s-string") {
        std::cout << "<!-- Benchmark SingleValueStringAttribute -->" << std::endl;
        ptr = AttributeFactory::createAttribute("s-string", AttrConfig(BasicType::STRING, CollectionType::SINGLE));
        benchmarkString(ptr);

    } else if (_config._attribute == "a-string") {
        std::cout << "<!-- Benchmark ArrayStringAttribute (array) -->" << std::endl;
        ptr = AttributeFactory::createAttribute("a-string", AttrConfig(BasicType::STRING, CollectionType::ARRAY));
        benchmarkString(ptr);

    } else if (_config._attribute == "ws-string") {
        std::cout << "<!-- Benchmark WeightedSetStringAttribute (wset) -->" << std::endl;
        ptr = AttributeFactory::createAttribute("ws-string", AttrConfig(BasicType::STRING, CollectionType::WSET));
        benchmarkString(ptr);

    } else if (_config._attribute == "s-fs-string") {
        std::cout << "<!-- Benchmark SingleValueStringPostingAttribute (single fast search) -->" << std::endl;
        AttrConfig cfg(BasicType::STRING, CollectionType::SINGLE);
        cfg.setFastSearch(true);
        ptr = AttributeFactory::createAttribute("s-fs-string", cfg);
        benchmarkString(ptr);

    } else if (_config._attribute == "a-fs-string") {
        std::cout << "<!-- Benchmark ArrayStringPostingAttribute (array fast search) -->" << std::endl;
        AttrConfig cfg(BasicType::STRING, CollectionType::ARRAY);
        cfg.setFastSearch(true);
        ptr = AttributeFactory::createAttribute("a-fs-string", cfg);
        benchmarkString(ptr);

    } else if (_config._attribute == "ws-fs-string") {
        std::cout << "<!-- Benchmark WeightedSetStringPostingAttribute (wset fast search) -->" << std::endl;
        AttrConfig cfg(BasicType::STRING, CollectionType::WSET);
        cfg.setFastSearch(true);
        ptr = AttributeFactory::createAttribute("ws-fs-string", cfg);
        benchmarkString(ptr);

    }

    if (dc._writeAttribute) {
        std::cout << "<!-- Writing attribute to disk -->" << std::endl;
        ptr->save(ptr->getBaseFileName());
    }

    std::cout << "</attribute-benchmark>" << std::endl;

    return 0;
}
}

int main(int argc, char **argv) {
    vespalib::SignalHandler::PIPE.ignore();
    search::AttributeBenchmark myapp;
    return myapp.main(argc, argv);
}