Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add compacted array benchmark tests #47

Closed
wants to merge 0 commits into from
Closed

Conversation

pengsven
Copy link

Description

add compacted array memory benchmark tests

Fixes #12

Type of change

  • Refactoring
  • Test changes

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

index := make([]uint32, 0, maxIdx)

for i := uint32(0); i < maxIdx; i++ {
if i%idxDis == 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for 后面 i += idxDis好不...

Dis开头的单词太多了...这里用Step感觉通俗简短点

}

func makeDisIndexes(maxIdx, idxDis uint32) []uint32 {
index := make([]uint32, 0, maxIdx)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

之后考虑优化下数组中数据特别稀疏的情况. 然后...等距的插入可能有些特殊性. 不方便日后做测试, 这里把间隔打乱下如何? 只保证平均间隔是idxDis. 实际每个间隔调整成idxDis*0.8 ~ idxDis * 1.2之间

return rss2 - rss1
}

func makeDiscrete(max uint32) []uint32 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discrete是啥意思在这里?

Copy link
Author

@pengsven pengsven Feb 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

离散的step


eltCnt := uint32(len(indexes))

fmt.Printf("%-10d%-10d%-10d%-10.3f\n", eltSize, eltCnt, idxDis, overhead)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

数字都用右对齐吧. 容易比较...

8 2 39602 1024 8155088 7963 16 497.688
8 2 64079 1024 12480560 12188 16 761.750
eltSize eltCount idxDis Overhead
1 65536 1 1.165
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

希望增加1列load-factor = 实际数据个数 / 最大id, 表示这个数组的稀疏的程度: 0~1;

一般这个比较容易看懂. idxDis也表示同样的信息,但还得换算一下.

overhead应该是额外内存开销的比例, 这里之前设置成总的开销 / 有效数据了.
overhead打印成+12%的形式可能更容易看懂.

1 9 8153 1382.111
1 5 14863 2487.800
1 3 27093 3461.000
1 2 49388 4935.500
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉idxDis还有点多, 手动配置几个有代表性的load-factor咋样? 对我来说关心的几个load-factor 是 1.0(满的) 0.5(半满), 0.2, 0.1, 0.01, 0.001.

}

func BenchmarkMemOverhead(b *testing.B) {
var cases = []struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

独立的只bench不做表格输出的函数还可以方便的在xx_test里调用吗? 想想那里如果能统一对所有东西bench下好像也不错...

Copy link
Author

@pengsven pengsven Feb 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

独立的bench是一个func Testxxx(t *testing.B)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该是一个func BenchXXX...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样?

func BenchX1(t *testing.B) {
}

func BenchX2(t *testing.B) {
}

func BenchX3(t *testing.B) {
}

func BenchXXX(t *testing.B) {
    t.Run("A=1", BenchX1)
    t.Run("A=2", BenchX2)
    t.Run("A=3", BenchX3)
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

额...当面说吧...

dataAvgSize := uint64(eltSize) * uint64(eltCnt)
actAvgSize := actSize / uint64(caCnt)

overHead := float64(actAvgSize) / float64(dataAvgSize)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉overhead的定义是float64(actAvgSize) / float64(dataAvgSize) - 1

@pengsven pengsven closed this Feb 26, 2019
@pengsven pengsven deleted the shuwen.array_benchmark branch March 5, 2019 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

array/: move report generator output bench. make it a standalone program.
2 participants