33,008
社区成员
发帖
与我相关
我的任务
分享
// DESCRIPTION for Fib.cpp :
// Defines the entry point for the console application.
// 目的:测试 GMP 与 HugeCalc 两大高精度算法库核心算法效率
// 因为计算 Fibonacci 本身可优化的地方不多,关键是大数乘法及大数平方,
// 故,通过测试 Fibonacci 效率而检测算法库最核心的大数乘法(平方)效率。
//
// 设计:郭先强 ( gxqcn@163.com; HugeCalc@Gmail.com )
// 日期:2008-01-03
//
// Web: http://www.emath.ac.cn/
// BBS: http://bbs.emath.ac.cn/
//
//////////////////////////////////////////////////////////////////////////
// Project -> Setting -> C/C++ -> Code Generation --> Use run-time library:
// Win32 Debug: Debug Multithreaded DLL
// Win32 Release: Multithreaded DLL
#include <iostream.h>
#include <gmp.h>
#include <HugeCalc.h> // 公共接口
#include <HugeInt.h> // 10进制系统
#include <HugeIntX.h> // 16进制系统
#pragma message( "automatic link to .../HugeCalc_API/CppAPI/Lib/HugeCalc.lib" )
#pragma comment( lib, "gmp.lib" )
#pragma comment( lib, "HugeCalc.lib" )
#if 0
# define FIRST_INDEX 10000000L /*1e7*/
#else
# define FIRST_INDEX 100000000L /*1e8*/
#endif
int main(int argc, char* argv[])
{
cout << "Call " << HugeCalc::GetVer() << endl;
if ( HC_LICENSE_NONE == HugeCalc::GetLicenseLevel() )
{
cout << "\r\n警告:您未通过 HugeCalc.dll 的许可认证!\r\n" \
<< "\r\n解决方案可选下列方案之一:" \
<< "\r\n 一、请将本程序移动到“/CopyrightByGuoXianqiang/[../]”目录下运行;" \
<< "\r\n 二、或请在 HugeCalc.chm 中进行注册(一劳永逸)。" \
<< endl;
}
else
{
for ( UINT32 u32Index = FIRST_INDEX; u32Index <= FIRST_INDEX * 4; u32Index <<= 1 )
{
cout << "\r\n--------------------------------\r\n" << endl;
cout << "Calculate Fib[" << u32Index << "]:\r\n" << endl;
#if 1
// 测试 GMP
{
mpz_t hugeFIB;
mpz_init( hugeFIB );
HugeCalc::EnableTimer( TRUE );
HugeCalc::ResetTimer();
mpz_fib_ui( hugeFIB, u32Index );
HugeCalc::EnableTimer( FALSE );
cout << "GMP used time: " << HugeCalc::GetTimerStr( FT_DOT06SEC_s ) << " ( " \
<< mpz_sizeinbase( hugeFIB, 2 ) << " Bits )" << endl;
mpz_clear( hugeFIB );
}
#endif
// 测试 HI
{
CHugeInt hugeFIB;
HugeCalc::EnableTimer( TRUE );
HugeCalc::ResetTimer();
hugeFIB.Fibonacci( u32Index );
HugeCalc::EnableTimer( FALSE );
cout << "HI used time: " << HugeCalc::GetTimerStr( FT_DOT06SEC_s ) << " ( " \
<< hugeFIB.GetDigits() << " Digits )" << endl;
}
// 测试 HX
{
CHugeIntX hugeFIB;
HugeCalc::EnableTimer( TRUE );
HugeCalc::ResetTimer();
hugeFIB.Fibonacci( u32Index );
HugeCalc::EnableTimer( FALSE );
cout << "HX used time: " << HugeCalc::GetTimerStr( FT_DOT06SEC_s ) << " ( " \
<< hugeFIB.GetBits() << " Bits )" << endl;
}
}
}
cout << endl;
system( "pause" );
return 0;
}