Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
d5904f4a
提交
d5904f4a
authored
7月 10, 2015
作者:
William King
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FS-7820 adding a unit test for switch_hash.c with benchmarking example
and docs
上级
8cb75a60
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
165 行增加
和
7 行删除
+165
-7
Makefile.am
tests/unit/Makefile.am
+10
-6
README
tests/unit/README
+14
-1
switch_hash.c
tests/unit/switch_hash.c
+141
-0
没有找到文件。
tests/unit/Makefile.am
浏览文件 @
d5904f4a
FSLD
=
$(top_builddir)
/libfreeswitch.la
$(top_builddir)
/libs/apr/libapr-1.la
$(top_builddir)
/libs/apr-util/libaprutil-1.la
TESTS
=
check_PROGRAMS
=
if
HAVE_TAP
TESTS
=
switch_event
if
HAVE_TAP
TESTS
+=
switch_event
check_PROGRAMS
=
switch_event
switch_event_SOURCES
=
switch_event.c
...
...
@@ -11,11 +13,13 @@ switch_event_CFLAGS = $(SWITCH_AM_CFLAGS)
switch_event_LDADD
=
$(FSLD)
switch_event_LDFLAGS
=
$(SWITCH_AM_LDFLAGS)
-ltap
event_create_SOURCES
=
event_create.c
event_create_CFLAGS
=
$(SWITCH_AM_CFLAGS)
event_create_LDADD
=
$(FSLD)
event_create_LDFLAGS
=
$(SWITCH_AM_LDFLAGS)
-ltap
TESTS
+=
switch_hash
check_PROGRAMS
+=
switch_hash
switch_hash_SOURCES
=
switch_hash.c
switch_hash_CFLAGS
=
$(SWITCH_AM_CFLAGS)
switch_hash_LDADD
=
$(FSLD)
switch_hash_LDFLAGS
=
$(SWITCH_AM_LDFLAGS)
-ltap
else
check
:
...
...
tests/unit/README
浏览文件 @
d5904f4a
...
...
@@ -15,4 +15,17 @@ test in a human and machine(regex) parsable format
Use libtap from https://github.com/zorgnax/libtap
cd /usr/local/src/
git clone https://github.com/zorgnax/libtap.git
make PREFIX=/usr install
\ No newline at end of file
make PREFIX=/usr install
To run a benchmark version of a unit test, update the loops count, and
make sure to uncomment the 'BENCHMARK' define line. Then you can run
the benchmark with:
perf record ./.libs/switch_hash
Once that is completed you can view the results with:
perf report
tests/unit/switch_hash.c
0 → 100644
浏览文件 @
d5904f4a
#include <stdio.h>
#include <switch.h>
#include <tap.h>
// #define BENCHMARK 1
int
main
()
{
switch_event_t
*
event
=
NULL
;
switch_bool_t
verbose
=
SWITCH_TRUE
;
const
char
*
err
=
NULL
;
switch_time_t
start_ts
,
end_ts
;
unsigned
long
long
micro_total
=
0
;
double
micro_per
=
0
;
double
rate_per_sec
=
0
;
#ifdef BENCHMARK
switch_time_t
small_start_ts
,
small_end_ts
;
#endif
int
rc
=
0
,
loops
=
10
;
switch_status_t
status
=
SWITCH_STATUS_SUCCESS
;
char
**
index
=
NULL
;
switch_hash_t
*
hash
=
NULL
;
#ifndef BENCHMARK
plan
(
2
+
(
5
*
loops
));
#else
plan
(
2
);
#endif
status
=
switch_core_init
(
SCF_MINIMAL
,
verbose
,
&
err
);
if
(
!
ok
(
status
==
SWITCH_STATUS_SUCCESS
,
"Initialize FreeSWITCH core
\n
"
))
{
bail_out
(
0
,
"Bail due to failure to initialize FreeSWITCH[%s]"
,
err
);
}
status
=
switch_core_hash_init
(
&
hash
);
if
(
!
ok
(
status
==
SWITCH_STATUS_SUCCESS
,
"Create a new hash"
))
{
bail_out
(
0
,
"Bail due to failure to create hash"
);
}
index
=
calloc
(
loops
,
sizeof
(
char
*
));
for
(
int
x
=
0
;
x
<
loops
;
x
++
)
{
index
[
x
]
=
switch_mprintf
(
"%d"
,
x
);
}
/* START LOOPS */
start_ts
=
switch_time_now
();
/* Insertion */
#ifndef BENCHMARK
for
(
int
x
=
0
;
x
<
loops
;
x
++
)
{
status
=
switch_core_hash_insert
(
hash
,
index
[
x
],
(
void
*
)
index
[
x
]);
ok
(
status
==
SWITCH_STATUS_SUCCESS
,
"Insert into the hash"
);
}
#else
small_start_ts
=
switch_time_now
();
for
(
int
x
=
0
;
x
<
loops
;
x
++
)
{
switch_core_hash_insert
(
hash
,
index
[
x
],
(
void
*
)
index
[
x
]);
}
small_end_ts
=
switch_time_now
();
micro_total
=
small_end_ts
-
small_start_ts
;
micro_per
=
micro_total
/
(
double
)
loops
;
rate_per_sec
=
1000000
/
micro_per
;
note
(
"switch_hash insert: Total %ldus / %ld loops, %.2f us per loop, %.0f loops per second
\n
"
,
micro_total
,
loops
,
micro_per
,
rate_per_sec
);
#endif
/* Lookup */
#ifndef BENCHMARK
for
(
int
x
=
0
;
x
<
loops
;
x
++
)
{
char
*
data
=
NULL
;
data
=
switch_core_hash_find
(
hash
,
index
[
x
]);
ok
(
data
!=
NULL
,
"Successful lookup"
);
is
(
index
[
x
],
data
,
"Returned correct data"
);
}
#else
small_start_ts
=
switch_time_now
();
for
(
int
x
=
0
;
x
<
loops
;
x
++
)
{
if
(
!
switch_core_hash_find
(
hash
,
index
[
x
]))
{
fail
(
"Failed to properly locate one of the values"
);
}
}
small_end_ts
=
switch_time_now
();
micro_total
=
small_end_ts
-
small_start_ts
;
micro_per
=
micro_total
/
(
double
)
loops
;
rate_per_sec
=
1000000
/
micro_per
;
note
(
"switch_hash find: Total %ldus / %ld loops, %.2f us per loop, %.0f loops per second
\n
"
,
micro_total
,
loops
,
micro_per
,
rate_per_sec
);
#endif
/* Delete */
#ifndef BENCHMARK
for
(
int
x
=
0
;
x
<
loops
;
x
++
)
{
char
*
data
=
NULL
;
data
=
switch_core_hash_delete
(
hash
,
index
[
x
]);
ok
(
data
!=
NULL
,
"Create a new hash"
);
is
(
index
[
x
],
data
,
"Returned correct data"
);
}
#else
small_start_ts
=
switch_time_now
();
for
(
int
x
=
0
;
x
<
loops
;
x
++
)
{
if
(
!
switch_core_hash_delete
(
hash
,
index
[
x
]))
{
fail
(
"Failed to delete and return the value"
);
}
}
small_end_ts
=
switch_time_now
();
micro_total
=
small_end_ts
-
small_start_ts
;
micro_per
=
micro_total
/
(
double
)
loops
;
rate_per_sec
=
1000000
/
micro_per
;
note
(
"switch_hash delete: Total %ldus / %d loops, %.2f us per loop, %.0f loops per second
\n
"
,
micro_total
,
loops
,
micro_per
,
rate_per_sec
);
#endif
end_ts
=
switch_time_now
();
/* END LOOPS */
switch_core_hash_destroy
(
&
hash
);
for
(
int
x
=
0
;
x
<
loops
;
x
++
)
{
free
(
index
[
x
]);
}
free
(
index
);
micro_total
=
end_ts
-
start_ts
;
micro_per
=
micro_total
/
(
double
)
loops
;
rate_per_sec
=
1000000
/
micro_per
;
note
(
"switch_hash Total %ldus / %d loops, %.2f us per loop, %.0f loops per second
\n
"
,
micro_total
,
loops
,
micro_per
,
rate_per_sec
);
switch_core_destroy
();
done_testing
();
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论