aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2012-02-20 21:12:29 +0000
committerlloyd <[email protected]>2012-02-20 21:12:29 +0000
commit49f333282279cc22fa8af7423447973b9dcfeee9 (patch)
tree574a19e310aeb158dcc08016b3ce91a9d0ac0f81 /src
parent73e7730306b524aeee6fcfe8dd9f41b9673cf31b (diff)
Remove get_nanoseconds_clock as we'll rely on std::chrono's high
resolution clock for this in C++11. Now that the only remaining function in time.h is calendar_point, rename the header to calendar.h. Hopefully that last use will go away once a TR2 datetime library becomes available. Use std::chrono inside the library benchmark code.
Diffstat (limited to 'src')
-rw-r--r--src/asn1/asn1_tm.cpp2
-rw-r--r--src/benchmark/benchmark.cpp26
-rw-r--r--src/cert/cvc/asn1_eac_tm.cpp2
-rw-r--r--src/cert/cvc/cvc_self.cpp1
-rw-r--r--src/tls/tls_session.cpp1
-rw-r--r--src/utils/calendar.cpp (renamed from src/utils/time.cpp)58
-rw-r--r--src/utils/calendar.h (renamed from src/utils/time.h)11
-rw-r--r--src/utils/info.txt4
8 files changed, 21 insertions, 84 deletions
diff --git a/src/asn1/asn1_tm.cpp b/src/asn1/asn1_tm.cpp
index 6e6868972..b8095a41c 100644
--- a/src/asn1/asn1_tm.cpp
+++ b/src/asn1/asn1_tm.cpp
@@ -10,7 +10,7 @@
#include <botan/ber_dec.h>
#include <botan/charset.h>
#include <botan/parsing.h>
-#include <botan/time.h>
+#include <botan/calendar.h>
namespace Botan {
diff --git a/src/benchmark/benchmark.cpp b/src/benchmark/benchmark.cpp
index f44aabb1f..a9b84f252 100644
--- a/src/benchmark/benchmark.cpp
+++ b/src/benchmark/benchmark.cpp
@@ -14,6 +14,7 @@
#include <memory>
#include <vector>
#include <chrono>
+
namespace Botan {
namespace {
@@ -24,19 +25,18 @@ typedef std::chrono::high_resolution_clock benchmark_clock;
* Benchmark Buffered_Computation (hash or MAC)
*/
std::pair<u64bit, u64bit> bench_buf_comp(Buffered_Computation* buf_comp,
- u64bit nanoseconds_max,
+ std::chrono::nanoseconds max_time,
const byte buf[], size_t buf_len)
{
u64bit reps = 0;
- std::chrono::nanoseconds max_time(nanoseconds_max);
std::chrono::nanoseconds time_used(0);
while(time_used < max_time)
{
auto start = benchmark_clock::now();
buf_comp->update(buf, buf_len);
- time_used += benchmark_clock::now() - start;
+ time_used += std::chrono::duration_cast<std::chrono::nanoseconds>(benchmark_clock::now() - start);
++reps;
}
@@ -52,14 +52,13 @@ std::pair<u64bit, u64bit> bench_buf_comp(Buffered_Computation* buf_comp,
*/
std::pair<u64bit, u64bit>
bench_block_cipher(BlockCipher* block_cipher,
- u64bit nanoseconds_max,
+ std::chrono::nanoseconds max_time,
byte buf[], size_t buf_len)
{
const size_t in_blocks = buf_len / block_cipher->block_size();
u64bit reps = 0;
- std::chrono::nanoseconds max_time(nanoseconds_max);
std::chrono::nanoseconds time_used(0);
block_cipher->set_key(buf, block_cipher->maximum_keylength());
@@ -68,7 +67,8 @@ bench_block_cipher(BlockCipher* block_cipher,
{
auto start = benchmark_clock::now();
block_cipher->encrypt_n(buf, buf, in_blocks);
- time_used += benchmark_clock::now() - start;
+ time_used += std::chrono::duration_cast<std::chrono::nanoseconds>(benchmark_clock::now() - start);
+ //time_used += benchmark_clock::now() - start;
++reps;
}
@@ -85,14 +85,13 @@ bench_block_cipher(BlockCipher* block_cipher,
*/
std::pair<u64bit, u64bit>
bench_stream_cipher(StreamCipher* stream_cipher,
- u64bit nanoseconds_max,
+ std::chrono::nanoseconds max_time,
byte buf[], size_t buf_len)
{
u64bit reps = 0;
stream_cipher->set_key(buf, stream_cipher->maximum_keylength());
- std::chrono::nanoseconds max_time(nanoseconds_max);
std::chrono::nanoseconds time_used(0);
while(time_used < max_time)
@@ -115,10 +114,10 @@ bench_stream_cipher(StreamCipher* stream_cipher,
*/
std::pair<u64bit, u64bit>
bench_hash(HashFunction* hash,
- u64bit nanoseconds_max,
+ std::chrono::nanoseconds max_time,
const byte buf[], size_t buf_len)
{
- return bench_buf_comp(hash, nanoseconds_max, buf, buf_len);
+ return bench_buf_comp(hash, max_time, buf, buf_len);
}
/**
@@ -126,11 +125,11 @@ bench_hash(HashFunction* hash,
*/
std::pair<u64bit, u64bit>
bench_mac(MessageAuthenticationCode* mac,
- u64bit nanoseconds_max,
+ std::chrono::nanoseconds max_time,
const byte buf[], size_t buf_len)
{
mac->set_key(buf, mac->maximum_keylength());
- return bench_buf_comp(mac, nanoseconds_max, buf, buf_len);
+ return bench_buf_comp(mac, max_time, buf, buf_len);
}
}
@@ -148,8 +147,7 @@ algorithm_benchmark(const std::string& name,
if(providers.empty()) // no providers, nothing to do
return all_results;
- const u64bit ns_per_provider =
- (static_cast<u64bit>(milliseconds) * 1000 * 1000) / providers.size();
+ std::chrono::nanoseconds ns_per_provider = milliseconds / providers.size();
std::vector<byte> buf(buf_size * 1024);
rng.randomize(&buf[0], buf.size());
diff --git a/src/cert/cvc/asn1_eac_tm.cpp b/src/cert/cvc/asn1_eac_tm.cpp
index ec5ac429e..12221b582 100644
--- a/src/cert/cvc/asn1_eac_tm.cpp
+++ b/src/cert/cvc/asn1_eac_tm.cpp
@@ -12,7 +12,7 @@
#include <botan/charset.h>
#include <botan/parsing.h>
#include <botan/internal/rounding.h>
-#include <botan/time.h>
+#include <botan/calendar.h>
namespace Botan {
diff --git a/src/cert/cvc/cvc_self.cpp b/src/cert/cvc/cvc_self.cpp
index 1646adeef..61a1e7b64 100644
--- a/src/cert/cvc/cvc_self.cpp
+++ b/src/cert/cvc/cvc_self.cpp
@@ -8,7 +8,6 @@
#include <botan/cvc_self.h>
#include <botan/ecc_key.h>
#include <botan/point_gfp.h>
-#include <botan/time.h>
#include <botan/oids.h>
#include <sstream>
#include <memory>
diff --git a/src/tls/tls_session.cpp b/src/tls/tls_session.cpp
index 6a485fd44..b27409dfa 100644
--- a/src/tls/tls_session.cpp
+++ b/src/tls/tls_session.cpp
@@ -10,7 +10,6 @@
#include <botan/ber_dec.h>
#include <botan/asn1_str.h>
#include <botan/pem.h>
-#include <botan/time.h>
namespace Botan {
diff --git a/src/utils/time.cpp b/src/utils/calendar.cpp
index d5b74828b..a51ef876c 100644
--- a/src/utils/time.cpp
+++ b/src/utils/calendar.cpp
@@ -1,36 +1,14 @@
/*
-* Time Functions
+* Calendar Functions
* (C) 1999-2010 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
-#include <botan/time.h>
+#include <botan/calendar.h>
#include <botan/exceptn.h>
#include <ctime>
-#if defined(BOTAN_TARGET_OS_HAS_WIN32_GET_SYSTEMTIME)
- #include <windows.h>
-#endif
-
-#if defined(BOTAN_TARGET_OS_HAS_GETTIMEOFDAY)
- #include <sys/time.h>
-#endif
-
-#if defined(BOTAN_TARGET_OS_HAS_CLOCK_GETTIME)
-
- #ifndef _POSIX_C_SOURCE
- #define _POSIX_C_SOURCE 199309
- #endif
-
- #include <time.h>
-
- #ifndef CLOCK_REALTIME
- #define CLOCK_REALTIME 0
- #endif
-
-#endif
-
namespace Botan {
namespace {
@@ -83,36 +61,4 @@ calendar_point calendar_value(
tm.tm_sec);
}
-u64bit get_nanoseconds_clock()
- {
-#if defined(BOTAN_TARGET_OS_HAS_CLOCK_GETTIME)
-
- struct ::timespec tv;
- ::clock_gettime(CLOCK_REALTIME, &tv);
- return combine_timers(tv.tv_sec, tv.tv_nsec, 1000000000);
-
-#elif defined(BOTAN_TARGET_OS_HAS_GETTIMEOFDAY)
-
- struct ::timeval tv;
- ::gettimeofday(&tv, 0);
- return combine_timers(tv.tv_sec, tv.tv_usec, 1000000);
-
-#elif defined(BOTAN_TARGET_OS_HAS_WIN32_GET_SYSTEMTIME)
-
- // Returns time since January 1, 1601 in 100-ns increments
- ::FILETIME tv;
- ::GetSystemTimeAsFileTime(&tv);
- u64bit tstamp = (static_cast<u64bit>(tv.dwHighDateTime) << 32) |
- tv.dwLowDateTime;
-
- return (tstamp * 100); // Scale to 1 nanosecond units
-
-#else
-
- return combine_timers(static_cast<u32bit>(std::time(0)),
- std::clock(), CLOCKS_PER_SEC);
-
-#endif
- }
-
}
diff --git a/src/utils/time.h b/src/utils/calendar.h
index 516efba3e..d617cc9a0 100644
--- a/src/utils/time.h
+++ b/src/utils/calendar.h
@@ -1,12 +1,12 @@
/*
-* Time Functions
+* Calendar Functions
* (C) 1999-2009 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
-#ifndef BOTAN_TIME_H__
-#define BOTAN_TIME_H__
+#ifndef BOTAN_CALENDAR_H__
+#define BOTAN_CALENDAR_H__
#include <botan/types.h>
#include <chrono>
@@ -58,11 +58,6 @@ struct BOTAN_DLL calendar_point
BOTAN_DLL calendar_point calendar_value(
const std::chrono::system_clock::time_point& time_point);
-/**
-* @return nanoseconds resolution timestamp, unknown epoch
-*/
-BOTAN_DLL u64bit get_nanoseconds_clock();
-
}
#endif
diff --git a/src/utils/info.txt b/src/utils/info.txt
index 4350ed410..e2ffd2714 100644
--- a/src/utils/info.txt
+++ b/src/utils/info.txt
@@ -4,11 +4,11 @@ load_on always
<source>
assert.cpp
+calendar.cpp
charset.cpp
cpuid.cpp
mlock.cpp
parsing.cpp
-time.cpp
version.cpp
</source>
@@ -24,6 +24,7 @@ xor_buf.h
<header:public>
bswap.h
+calendar.h
charset.h
cpuid.h
exceptn.h
@@ -31,7 +32,6 @@ loadstor.h
mem_ops.h
parsing.h
rotate.h
-time.h
types.h
version.h
get_byte.h