]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
hsbench: add hyphen support for -T option
authorHong, Yang A <yang.a.hong@intel.com>
Tue, 28 Apr 2020 10:14:55 +0000 (10:14 +0000)
committerHong, Yang A <yang.a.hong@intel.com>
Mon, 25 May 2020 13:47:53 +0000 (13:47 +0000)
tools/hsbench/main.cpp
util/string_util.h

index 8e85d7aea55ae3f98ce57c3da52c848bbe8af698..4e65c8e0bc6a02bc63426318246d44802b664e09 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016-2019, Intel Corporation
+ * Copyright (c) 2016-2020, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -207,7 +207,9 @@ void usage(const char *error) {
     printf("  -P              Benchmark using PCRE (if supported).\n");
 #endif
 #if defined(HAVE_DECL_PTHREAD_SETAFFINITY_NP) || defined(_WIN32)
-    printf("  -T CPU,CPU,...  Benchmark with threads on these CPUs.\n");
+    printf("  -T CPU,CPU,... or -T CPU-CPU\n");
+    printf("                  Benchmark with threads on specified CPUs or CPU"
+           " range.\n");
 #endif
     printf("  -i DIR          Don't compile, load from files in DIR"
            " instead.\n");
@@ -354,7 +356,8 @@ void processArgs(int argc, char *argv[], vector<BenchmarkSigs> &sigSets,
         case 'T':
             if (!strToList(optarg, threadCores)) {
                 usage("Couldn't parse argument to -T flag, should be"
-                      " a list of positive integers.");
+                      " a list of positive integers or 2 integers"
+                      " connected with hyphen.");
                 exit(1);
             }
             break;
index b44586ea75b2a1ac9082d295b5241e212866f2ae..ab3751c1feab8971e303e6915754a033fdb250c2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2019, Intel Corporation
+ * Copyright (c) 2015-2020, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -54,8 +54,8 @@ inline bool fromString(const std::string &s, T& val)
     return true;
 }
 
-// read in a comma-separated set of values: very simple impl, not for
-// external consumption
+// read in a comma-separated or hyphen-connected set of values: very simple
+// impl, not for external consumption
 template<typename T>
 inline bool strToList(const std::string &s, std::vector<T>& out)
 {
@@ -68,7 +68,17 @@ inline bool strToList(const std::string &s, std::vector<T>& out)
         }
 
         out.push_back(val);
-    } while (i.get(c) && c == ',');
+
+        i.get(c);
+        if (c == '-') {
+            T val_end;
+            i >> val_end;
+            while (val < val_end) {
+                out.push_back(++val);
+            }
+            break;
+        }
+    } while (c == ',');
 
     return !out.empty();
 }