append_zero 浮点和double补充0 库函数PK自己写的函数效率对比
来源:互联网 发布:大数据 医学的统计 编辑:程序博客网 时间:2024/06/04 19:16
define USING_LOG_PREFIX RPC_TEST
include
include “rpc/obmysql/ob_mysql_util.h”
using namespace oceanbase::common;
using namespace oceanbase::obmysql;
class TestDoubleZeroFill
: public ::testing::Test
{
public:
TestDoubleZeroFill()
{}
virtual void SetUp()
{
}
virtual void TearDown()
{
}
void zero_fill_libraries(char *buf, int64_t &length, int16_t scale)
{
if (scale > 0) {
int point = 0;
const char *findponit = buf;
const char *pot = strchr(findponit,’.’);
if (pot !=NULL)
{
point = static_cast(pot - findponit);
} else {
point = static_cast(length);
}
if (point == length) {
// *(buf + length) = ‘.’;
memcpy(buf+ length, “.”, 1);
length ++;
}
memset(buf + length, ‘0’, scale + 1 - length + point);
length += scale + 1 - length - point;
*(buf + length) = ‘\0’;
}
}
void ObMySQLUtil::zero_fill(char *buf, int64_t &length, int16_t scale)
{
if (scale > 0) {
int point = 0;
for (;*(buf + point) != ‘.’ && point < length; point ++) { }
if (point == length) {
*(buf + length) = ‘.’;
length ++;
}
for (int64_t i = length-point; (scale - i + 1) >0; i++) {
*(buf + length) = ‘0’;
length ++;
}
*(buf + length) = ‘\0’;
}
}
protected:
};
TEST_F(TestDoubleZeroFill, TestFillZero)
{
const char org = (const char )”623423.234”;
char buf[64];
int64_t char_size = strlen(org);
int16_t scale = 10;
const char *org_1 = (const char *)"3.2"; int64_t char_size_1 = strlen(org_1); int16_t scale_1 = 2; int64_t total_my = 0; int64_t total_lib = 0; for (int j = 0; j<5; j++) { memset(buf, 0, 64); memcpy(buf, org, char_size); const int64_t start_ts_my = ObTimeUtility::current_time(); for (int i = 0; i < 100000000; i++) { zero_fill(buf, char_size, scale); } const int64_t end_ts_my = ObTimeUtility::current_time(); memset(buf, 0, 64); memcpy(buf, org, char_size); const int64_t start_ts_lib = ObTimeUtility::current_time(); for (int i = 0; i < 100000000; i++) { zero_fill_libraries(buf, char_size, scale); } const int64_t end_ts_lib = ObTimeUtility::current_time(); total_my += end_ts_my - start_ts_my; total_lib += end_ts_lib - start_ts_lib; memset(buf, 0, 64); memcpy(buf, org_1, char_size_1); const int64_t start_ts_my_1 = ObTimeUtility::current_time(); for (int i = 0; i < 100000000; i++) { zero_fill(buf, char_size_1, scale_1); } const int64_t end_ts_my_1 = ObTimeUtility::current_time(); memset(buf, 0, 64); memcpy(buf, org_1, char_size_1); const int64_t start_ts_lib_1 = ObTimeUtility::current_time(); for (int i = 0; i < 100000000; i++) { zero_fill_libraries(buf, char_size_1, scale_1); } const int64_t end_ts_lib_1 = ObTimeUtility::current_time(); total_my += end_ts_my_1 - start_ts_my_1; total_lib += end_ts_lib_1 - start_ts_lib_1; } LOG_INFO("cmp, ob vs lib", K(total_my), K(total_lib));
}
int main(int argc, char *argv[])
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
- append_zero 浮点和double补充0 库函数PK自己写的函数效率对比
- 浮点数float和double的精度
- 自己写的部分CI框架库函数
- 自己模拟strcpy库函数写的功能函数my_strcpy实现strcpy的功能,完整代码
- 自己模拟strcat库函数写的功能函数my_strcat实现strcat的功能,完整代码
- 自己模拟strlen库函数写的功能函数my_strlen实现strlen的功能,完整代码
- 自己模拟strcmp库函数写的功能函数my_strcmp实现strcmp的功能,完整代码
- 写一个double my_atof(char *str)函数,将一个数字字符串转换成对应的浮点数
- 系统调用与库函数对于不同buffer size写文件效率对比
- double和long long 的精度对比
- 定点dsp和浮点dsp的对比
- 定点dsp和浮点dsp的对比
- 自己写的内存池效率评测
- 不区分大小写的字符穿搜索函数,自己写的,效率比StrStrI要高
- 浮点数 float和double
- 验证matlab的diff函数比自己写c效率高很多
- 【C语言】[库函数]:printf 函数 和 scanf 函数 对float 和double 类型打印和读取
- swap()函数效率对比
- Meteor methods call apply 使用
- Kettle学习1
- Freemarker 使用
- RUNTIME_CLASS(运行时间类)
- OC 属性
- append_zero 浮点和double补充0 库函数PK自己写的函数效率对比
- linux tee 命令
- 地图与定位
- zk 原理 watcher 监听
- 如何装win10 1511最新官方版(U盘装新系统)16年3月30日更新了可用激活
- 1.redis学习笔记:redis数据库的安装
- memcache查看数据命令
- 文件下载、打包下载的问题汇总
- Android Studio 如果调用外部包(20151125)