MCPcopy Create free account
hub / github.com/dmlc/dmlc-core / main

Function main

test/csv_parser_test.cc:8–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6#include "../src/data/csv_parser.h"
7
8int main(int argc, char *argv[]) {
9 if (argc < 5) {
10 printf("Usage: <libsvm> partid npart nthread [dump csv]\n");
11 return 0;
12 }
13 FILE *fo = NULL;
14 if (argc > 5) {
15 if (!strcmp(argv[5], "stdout")) {
16 fo = stdout;
17 } else {
18 fo = fopen(argv[5], "w");
19 }
20 }
21 using namespace dmlc;
22 std::unique_ptr<dmlc::Parser<unsigned, int> > parser(
23 dmlc::Parser<unsigned, int>::Create(argv[1],
24 atoi(argv[2]),
25 atoi(argv[3]),
26 "csv"));
27 double tstart = GetTime();
28 size_t bytes_read = 0;
29 size_t bytes_expect = 10UL << 20UL;
30 size_t num_ex = 0;
31 while (parser->Next());
32 parser->BeforeFirst();
33 while (parser->Next()) {
34 bytes_read = parser->BytesRead();
35 num_ex += parser->Value().size;
36 if (fo != NULL){
37 const dmlc::RowBlock<unsigned, int>& batch = parser->Value();
38 for (size_t i = 0; i < batch.size; ++i) {
39 for (size_t j = 0; j < batch[i].length; ++j) {
40 fprintf(fo, "%d", batch[i].value[j]);
41 if (j + 1 == batch[i].length) {
42 fprintf(fo, "\n");
43 } else {
44 fprintf(fo, ",");
45 }
46 }
47 }
48 }
49 double tdiff = GetTime() - tstart;
50 if (bytes_read >= bytes_expect) {
51 printf("%lu examples, %lu MB read, %g MB/sec\n",
52 num_ex, bytes_read >> 20UL,
53 (bytes_read >> 20UL) / tdiff);
54 bytes_expect += 10UL << 20UL;
55 }
56 }
57 if (fo != NULL && fo != stdout) {
58 fclose(fo);
59 }
60 return 0;
61}

Callers

nothing calls this directly

Calls 4

GetTimeFunction · 0.85
NextMethod · 0.45
BeforeFirstMethod · 0.45
BytesReadMethod · 0.45

Tested by

no test coverage detected