📄 bench_8cpp-source.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>Crypto++: bench.cpp Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.3.2 --><div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Compound List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="namespacemembers.html">Namespace Members</a> | <a class="qindex" href="functions.html">Compound Members</a> | <a class="qindex" href="globals.html">File Members</a></div><h1>bench.cpp</h1><div class="fragment"><pre>00001 <span class="comment">// bench.cpp - written and placed in the public domain by Wei Dai</span>00002 00003 <span class="preprocessor">#include "pch.h"</span>00004 00005 <span class="preprocessor">#include "crc.h"</span>00006 <span class="preprocessor">#include "adler32.h"</span>00007 <span class="preprocessor">#include "md2.h"</span>00008 <span class="preprocessor">#include "md5.h"</span>00009 <span class="preprocessor">#include "<a class="code" href="md5mac_8h.html">md5mac.h</a>"</span>00010 <span class="preprocessor">#include "sha.h"</span>00011 <span class="preprocessor">#include "haval.h"</span>00012 <span class="preprocessor">#include "tiger.h"</span>00013 <span class="preprocessor">#include "ripemd.h"</span>00014 <span class="preprocessor">#include "panama.h"</span>00015 <span class="preprocessor">#include "<a class="code" href="idea_8h.html">idea.h</a>"</span>00016 <span class="preprocessor">#include "<a class="code" href="des_8h.html">des.h</a>"</span>00017 <span class="preprocessor">#include "<a class="code" href="rc2_8h.html">rc2.h</a>"</span>00018 <span class="preprocessor">#include "arc4.h"</span>00019 <span class="preprocessor">#include "<a class="code" href="rc5_8h.html">rc5.h</a>"</span>00020 <span class="preprocessor">#include "<a class="code" href="blowfish_8h.html">blowfish.h</a>"</span>00021 <span class="preprocessor">#include "<a class="code" href="diamond_8h.html">diamond.h</a>"</span>00022 <span class="preprocessor">#include "wake.h"</span>00023 <span class="preprocessor">#include "<a class="code" href="3way_8h.html">3way.h</a>"</span>00024 <span class="preprocessor">#include "<a class="code" href="safer_8h.html">safer.h</a>"</span>00025 <span class="preprocessor">#include "<a class="code" href="gost_8h.html">gost.h</a>"</span>00026 <span class="preprocessor">#include "<a class="code" href="shark_8h.html">shark.h</a>"</span>00027 <span class="preprocessor">#include "<a class="code" href="cast_8h.html">cast.h</a>"</span>00028 <span class="preprocessor">#include "<a class="code" href="square_8h.html">square.h</a>"</span>00029 <span class="preprocessor">#include "<a class="code" href="skipjack_8h.html">skipjack.h</a>"</span>00030 <span class="preprocessor">#include "seal.h"</span>00031 <span class="preprocessor">#include "<a class="code" href="rc6_8h.html">rc6.h</a>"</span>00032 <span class="preprocessor">#include "<a class="code" href="mars_8h.html">mars.h</a>"</span>00033 <span class="preprocessor">#include "<a class="code" href="rijndael_8h.html">rijndael.h</a>"</span>00034 <span class="preprocessor">#include "<a class="code" href="twofish_8h.html">twofish.h</a>"</span>00035 <span class="preprocessor">#include "<a class="code" href="serpent_8h.html">serpent.h</a>"</span>00036 <span class="preprocessor">#include "hmac.h"</span>00037 <span class="preprocessor">#include "xormac.h"</span>00038 <span class="preprocessor">#include "cbcmac.h"</span>00039 <span class="preprocessor">#include "dmac.h"</span>00040 <span class="preprocessor">#include "blumshub.h"</span>00041 <span class="preprocessor">#include "<a class="code" href="rsa_8h.html">rsa.h</a>"</span>00042 <span class="preprocessor">#include "nr.h"</span>00043 <span class="preprocessor">#include "<a class="code" href="dsa_8h.html">dsa.h</a>"</span>00044 <span class="preprocessor">#include "<a class="code" href="luc_8h.html">luc.h</a>"</span>00045 <span class="preprocessor">#include "<a class="code" href="rabin_8h.html">rabin.h</a>"</span>00046 <span class="preprocessor">#include "<a class="code" href="rw_8h.html">rw.h</a>"</span>00047 <span class="preprocessor">#include "<a class="code" href="eccrypto_8h.html">eccrypto.h</a>"</span>00048 <span class="preprocessor">#include "ecp.h"</span>00049 <span class="preprocessor">#include "ec2n.h"</span>00050 <span class="preprocessor">#include "asn.h"</span>00051 <span class="preprocessor">#include "rng.h"</span>00052 <span class="preprocessor">#include "files.h"</span>00053 <span class="preprocessor">#include "hex.h"</span>00054 <span class="preprocessor">#include "<a class="code" href="modes_8h.html">modes.h</a>"</span>00055 <span class="preprocessor">#include "<a class="code" href="mdc_8h.html">mdc.h</a>"</span>00056 <span class="preprocessor">#include "<a class="code" href="lubyrack_8h.html">lubyrack.h</a>"</span>00057 <span class="preprocessor">#include "sapphire.h"</span>00058 <span class="preprocessor">#include "<a class="code" href="tea_8h.html">tea.h</a>"</span>00059 <span class="preprocessor">#include "<a class="code" href="dh_8h.html">dh.h</a>"</span>00060 <span class="preprocessor">#include "<a class="code" href="mqv_8h.html">mqv.h</a>"</span>00061 <span class="preprocessor">#include "<a class="code" href="xtrcrypt_8h.html">xtrcrypt.h</a>"</span>00062 <span class="preprocessor">#include "<a class="code" href="esign_8h.html">esign.h</a>"</span>00063 00064 <span class="preprocessor">#include "bench.h"</span>00065 00066 <span class="preprocessor">#include <time.h></span>00067 <span class="preprocessor">#include <math.h></span>00068 <span class="preprocessor">#include <iostream></span>00069 <span class="preprocessor">#include <iomanip></span>00070 00071 USING_NAMESPACE(CryptoPP)00072 USING_NAMESPACE(std)00073 00074 #ifdef CLOCKS_PER_SEC00075 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">double</span> CLOCK_TICKS_PER_SECOND = (<span class="keywordtype">double</span>)CLOCKS_PER_SEC;00076 <span class="preprocessor">#elif defined(CLK_TCK)</span>00077 <span class="preprocessor"></span><span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">double</span> CLOCK_TICKS_PER_SECOND = (<span class="keywordtype">double</span>)CLK_TCK;00078 <span class="preprocessor">#else</span>00079 <span class="preprocessor"></span><span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">double</span> CLOCK_TICKS_PER_SECOND = 1000000.0;00080 <span class="preprocessor">#endif</span>00081 <span class="preprocessor"></span>00082 <span class="keyword">static</span> <span class="keyword">const</span> byte *<span class="keyword">const</span> key=(byte *)<span class="stringliteral">"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"</span>;00083 00084 <span class="keyword">static</span> <span class="keywordtype">double</span> logtotal = 0;00085 <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> logcount = 0;00086 00087 <span class="keywordtype">void</span> OutputResultBytes(<span class="keyword">const</span> <span class="keywordtype">char</span> *name, <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> length, <span class="keywordtype">double</span> timeTaken)00088 {00089 <span class="keywordtype">double</span> mbs = length / timeTaken / (1024*1024);00090 cout << <span class="stringliteral">"<TR><TH>"</span> << name;00091 cout << <span class="stringliteral">"<TD>"</span> << length;00092 cout << setiosflags(ios::fixed);00093 cout << <span class="stringliteral">"<TD>"</span> << setprecision(3) << timeTaken;00094 cout << <span class="stringliteral">"<TD>"</span> << setprecision(3) << mbs << endl;00095 cout << resetiosflags(ios::fixed);00096 logtotal += log(mbs);00097 logcount++;00098 }00099 00100 <span class="keywordtype">void</span> OutputResultOperations(<span class="keyword">const</span> <span class="keywordtype">char</span> *name, <span class="keyword">const</span> <span class="keywordtype">char</span> *operation, <span class="keywordtype">bool</span> pc, <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> iterations, <span class="keywordtype">double</span> timeTaken)00101 {00102 cout << <span class="stringliteral">"<TR><TH>"</span> << name << <span class="stringliteral">" "</span> << operation << (pc ? <span class="stringliteral">" with precomputation"</span> : <span class="stringliteral">""</span>);00103 cout << <span class="stringliteral">"<TD>"</span> << iterations;00104 cout << setiosflags(ios::fixed);00105 cout << <span class="stringliteral">"<TD>"</span> << setprecision(3) << timeTaken;00106 cout << <span class="stringliteral">"<TD>"</span> << setprecision(2) << (1000*timeTaken/iterations) << endl;00107 cout << resetiosflags(ios::fixed);00108 00109 logtotal += log(iterations/timeTaken);00110 logcount++;00111 }00112 00113 <span class="keywordtype">void</span> BenchMark(<span class="keyword">const</span> <span class="keywordtype">char</span> *name, <a class="code" href="class_block_transformation.html">BlockTransformation</a> &cipher, <span class="keywordtype">double</span> timeTotal)00114 {00115 <span class="keyword">const</span> <span class="keywordtype">int</span> BUF_SIZE = RoundDownToMultipleOf(1024U, cipher.<a class="code" href="class_block_transformation.html#_twofish_1_1_enca14">OptimalNumberOfParallelBlocks</a>() * cipher.<a class="code" href="class_block_transformation.html#_simple_keying_interface_impl_3_01_s_a_f_e_r_1_1_enc_00_01_s_a_f_e_r___s_k___info_01_4a10">BlockSize</a>());00116 <a class="code" href="class_sec_block.html">SecByteBlock</a> buf(BUF_SIZE);00117 <span class="keyword">const</span> <span class="keywordtype">int</span> nBlocks = BUF_SIZE / cipher.<a class="code" href="class_block_transformation.html#_simple_keying_interface_impl_3_01_s_a_f_e_r_1_1_enc_00_01_s_a_f_e_r___s_k___info_01_4a10">BlockSize</a>();00118 clock_t start = clock();00119 00120 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> i=0, length=BUF_SIZE;00121 <span class="keywordtype">double</span> timeTaken;00122 <span class="keywordflow">do</span>00123 {00124 length *= 2;00125 <span class="keywordflow">for</span> (; i<length; i+=BUF_SIZE)00126 cipher.<a class="code" href="class_block_transformation.html#_twofish_1_1_enca15">ProcessAndXorMultipleBlocks</a>(buf, NULL, buf, nBlocks);00127 timeTaken = double(clock() - start) / CLOCK_TICKS_PER_SECOND;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -