add benchmark code.

It's about 3x faster than kaldi for a wave with duration 320 seconds on
CPU.
This commit is contained in:
Fangjun Kuang 2021-02-27 00:33:48 +08:00
parent 7c8ef68bb5
commit 917df77946
2 changed files with 17 additions and 3 deletions

View File

@ -4,6 +4,8 @@
#include "kaldifeat/python/csrc/kaldifeat.h"
#include <chrono>
#include "kaldifeat/csrc/feature-fbank.h"
#include "torch/torch.h"
@ -19,7 +21,19 @@ PYBIND11_MODULE(_kaldifeat, m) {
Fbank fbank(fbank_opts);
float vtln_warp = 1.0f;
std::chrono::steady_clock::time_point begin =
std::chrono::steady_clock::now();
torch::Tensor ans = fbank.ComputeFeatures(tensor, vtln_warp);
std::chrono::steady_clock::time_point end =
std::chrono::steady_clock::now();
std::cout << "Time difference = "
<< std::chrono::duration_cast<std::chrono::microseconds>(end -
begin)
.count() /
1000000.
<< "[s]" << std::endl;
return ans;
});
}

View File

@ -22,9 +22,9 @@ def main():
a *= 32768
tensor = torch.from_numpy(a)
ans = _kaldifeat.test(tensor)
torch.set_printoptions(profile="full")
print(ans.shape)
print(ans)
# torch.set_printoptions(profile="full")
# print(ans.shape)
# print(ans)
if __name__ == '__main__':