restore formatting flags after use

This commit is contained in:
Matthew Barr 2017-06-19 15:52:08 +10:00
parent 3d58ce83bd
commit c7f3150141

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015-2016, Intel Corporation * Copyright (c) 2015-2017, Intel Corporation
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -165,6 +165,7 @@ static bool higher_is_better(Criterion c) {
} }
static void print_criterion(Criterion c, double val) { static void print_criterion(Criterion c, double val) {
std::ios::fmtflags f(cout.flags());
switch (c) { switch (c) {
case CRITERION_THROUGHPUT: case CRITERION_THROUGHPUT:
cout << std::fixed << std::setprecision(3) << val << " Megabits/s"; cout << std::fixed << std::setprecision(3) << val << " Megabits/s";
@ -179,6 +180,7 @@ static void print_criterion(Criterion c, double val) {
cout << static_cast<size_t>(val) << " bytes"; cout << static_cast<size_t>(val) << " bytes";
break; break;
} }
cout.flags(f);
} }
// Key for identifying a stream in our pcap input data, using data from its IP // Key for identifying a stream in our pcap input data, using data from its IP
@ -596,11 +598,13 @@ double eval_set(Benchmark &bench, Sigdata &sigs, unsigned int mode,
size_t bytes = bench.bytes(); size_t bytes = bench.bytes();
size_t matches = bench.matches(); size_t matches = bench.matches();
if (diagnose) { if (diagnose) {
std::ios::fmtflags f(cout.flags());
cout << "Scan time " << std::fixed << std::setprecision(3) << scan_time cout << "Scan time " << std::fixed << std::setprecision(3) << scan_time
<< " sec, Scanned " << bytes * repeatCount << " bytes, Throughput " << " sec, Scanned " << bytes * repeatCount << " bytes, Throughput "
<< std::fixed << std::setprecision(3) << std::fixed << std::setprecision(3)
<< (bytes * 8 * repeatCount) / (scan_time * 1000000) << (bytes * 8 * repeatCount) / (scan_time * 1000000)
<< " Mbps, Matches " << matches << endl; << " Mbps, Matches " << matches << endl;
cout.flags(f);
} }
return (bytes * 8 * repeatCount) / (scan_time * 1000000); return (bytes * 8 * repeatCount) / (scan_time * 1000000);
} }
@ -755,10 +759,12 @@ int main(int argc, char **argv) {
for (unsigned i = count; i < 16; i++) { for (unsigned i = count; i < 16; i++) {
cout << " "; cout << " ";
} }
std::ios::fmtflags out_f(cout.flags());
cout << "Performance: "; cout << "Performance: ";
print_criterion(criterion, best); print_criterion(criterion, best);
cout << " (" << std::fixed << std::setprecision(3) << (best / score_base) cout << " (" << std::fixed << std::setprecision(3) << (best / score_base)
<< "x) after cutting:" << endl; << "x) after cutting:" << endl;
cout.flags(out_f);
// s now has factor_max signatures // s now has factor_max signatures
for (const auto &found : s) { for (const auto &found : s) {