mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-25 12:52:29 +03:00
Tetsuo's two patches
This commit is contained in:
parent
b5bb500773
commit
59bd7deb4b
@ -25,7 +25,7 @@ uint64_t HashForVocab(const char *str, std::size_t len);
|
||||
inline uint64_t HashForVocab(const StringPiece &str) {
|
||||
return HashForVocab(str.data(), str.length());
|
||||
}
|
||||
class ProbingVocabularyHeader;
|
||||
struct ProbingVocabularyHeader;
|
||||
} // namespace detail
|
||||
|
||||
class WriteWordsWrapper : public EnumerateVocab {
|
||||
|
@ -21,6 +21,21 @@ namespace util {
|
||||
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
namespace {
|
||||
|
||||
// On Mac OS X, clock_gettime is not implemented.
|
||||
// CLOCK_MONOTONIC is not defined either.
|
||||
#ifdef __MACH__
|
||||
#define CLOCK_MONOTONIC 0
|
||||
|
||||
int clock_gettime(int clk_id, struct timespec *tp) {
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
tp->tv_sec = tv.tv_sec;
|
||||
tp->tv_nsec = tv.tv_usec * 1000;
|
||||
return 0;
|
||||
}
|
||||
#endif // __MACH__
|
||||
|
||||
float FloatSec(const struct timeval &tv) {
|
||||
return static_cast<float>(tv.tv_sec) + (static_cast<float>(tv.tv_usec) / 1000000.0);
|
||||
}
|
||||
@ -36,9 +51,7 @@ const char *SkipSpaces(const char *at) {
|
||||
class RecordStart {
|
||||
public:
|
||||
RecordStart() {
|
||||
#ifdef CLOCK_MONOTONIC
|
||||
clock_gettime(CLOCK_MONOTONIC, &started_);
|
||||
#endif
|
||||
}
|
||||
|
||||
const struct timespec &Started() const {
|
||||
@ -79,9 +92,7 @@ void PrintUsage(std::ostream &out) {
|
||||
out << "CPU:" << (FloatSec(usage.ru_utime) + FloatSec(usage.ru_stime));
|
||||
|
||||
struct timespec current;
|
||||
#ifdef CLOCK_MONOTONIC
|
||||
clock_gettime(CLOCK_MONOTONIC, ¤t);
|
||||
#endif
|
||||
out << "\treal:" << (FloatSec(current) - FloatSec(kRecordStart.Started())) << '\n';
|
||||
#endif
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user