diff options
author | josh.macdonald <jmacd@users.noreply.github.com> | 2014-04-03 05:45:20 +0000 |
---|---|---|
committer | josh.macdonald <jmacd@users.noreply.github.com> | 2014-04-03 05:45:20 +0000 |
commit | 7b6ff92bf4f954b70f92b04eadcf43fe69403cc8 (patch) | |
tree | 45a14166d69eb9c4d0f5b30784c17c590fbb0014 /xdelta3 | |
parent | 81498dea08759883b4bfdb3335a95da92c9278dd (diff) |
Revert recent (unreleased) change in hash_value formula; make several tests use the average over 16 runs
Diffstat (limited to 'xdelta3')
-rw-r--r-- | xdelta3/testing/random.h | 2 | ||||
-rw-r--r-- | xdelta3/testing/regtest.cc | 145 | ||||
-rw-r--r-- | xdelta3/xdelta3.c | 2 |
3 files changed, 83 insertions, 66 deletions
diff --git a/xdelta3/testing/random.h b/xdelta3/testing/random.h index d1a6840..8ff64db 100644 --- a/xdelta3/testing/random.h +++ b/xdelta3/testing/random.h | |||
@@ -21,7 +21,7 @@ class MTRandom { | |||
21 | Init(TEST_SEED1); | 21 | Init(TEST_SEED1); |
22 | } | 22 | } |
23 | 23 | ||
24 | MTRandom(uint32_t seed) { | 24 | explicit MTRandom(uint32_t seed) { |
25 | Init(seed); | 25 | Init(seed); |
26 | } | 26 | } |
27 | 27 | ||
diff --git a/xdelta3/testing/regtest.cc b/xdelta3/testing/regtest.cc index 7f9ba52..84ee100 100644 --- a/xdelta3/testing/regtest.cc +++ b/xdelta3/testing/regtest.cc | |||
@@ -16,7 +16,7 @@ public: | |||
16 | iopt_size(XD3_DEFAULT_IOPT_SIZE), | 16 | iopt_size(XD3_DEFAULT_IOPT_SIZE), |
17 | smatch_cfg(XD3_SMATCH_DEFAULT) { } | 17 | smatch_cfg(XD3_SMATCH_DEFAULT) { } |
18 | 18 | ||
19 | size_t encode_srcwin_maxsz; | 19 | xoff_t encode_srcwin_maxsz; |
20 | size_t block_size; | 20 | size_t block_size; |
21 | bool size_known; | 21 | bool size_known; |
22 | usize_t iopt_size; | 22 | usize_t iopt_size; |
@@ -814,41 +814,51 @@ void TestCopyWindow() { | |||
814 | const int clen = 16; | 814 | const int clen = 16; |
815 | const int size = 4096; | 815 | const int size = 4096; |
816 | const int nmov = size / clen; | 816 | const int nmov = size / clen; |
817 | MTRandom rand; | 817 | const int iters = 16; |
818 | FileSpec spec0(&rand); | 818 | uint32_t added_01 = 0; |
819 | ChangeList cl; | 819 | uint32_t added_10 = 0; |
820 | 820 | for (int i = 1; i <= iters; i++) { | |
821 | spec0.GenerateFixedSize(size); | 821 | MTRandom rand(MTRandom::TEST_SEED1 * i); |
822 | 822 | FileSpec spec0(&rand); | |
823 | for (int j = 0; j < nmov; j += 2) | 823 | ChangeList cl; |
824 | { | ||
825 | cl.push_back(Change(Change::MOVE, | ||
826 | clen, (j + 1) * clen, j * clen)); | ||
827 | } | ||
828 | |||
829 | FileSpec spec1(&rand); | ||
830 | spec0.ModifyTo(ChangeListMutator(cl), &spec1); | ||
831 | 824 | ||
832 | Options options; | 825 | spec0.GenerateFixedSize(size); |
833 | options.encode_srcwin_maxsz = size; | ||
834 | options.iopt_size = 128; | ||
835 | options.smatch_cfg = XD3_SMATCH_SLOW; | ||
836 | options.size_known = false; | ||
837 | |||
838 | Block block1; | ||
839 | InMemoryEncodeDecode(spec0, spec1, &block1, options); | ||
840 | Delta delta1(block1); | ||
841 | CHECK_EQ(0, delta1.AddedBytes()); | ||
842 | 826 | ||
843 | Block block2; | 827 | for (int j = 0; j < nmov; j += 2) |
844 | InMemoryEncodeDecode(spec1, spec0, &block2, options); | 828 | { |
845 | Delta delta2(block2); | 829 | cl.push_back(Change(Change::MOVE, |
846 | CHECK_EQ(0, delta2.AddedBytes()); | 830 | clen, (j + 1) * clen, j * clen)); |
831 | } | ||
847 | 832 | ||
848 | Block block3; | 833 | FileSpec spec1(&rand); |
849 | Block block4; | 834 | spec0.ModifyTo(ChangeListMutator(cl), &spec1); |
850 | EncodeDecodeAPI(spec0, spec1, &block3, options); | 835 | |
851 | EncodeDecodeAPI(spec1, spec0, &block4, options); | 836 | Options options; |
837 | options.encode_srcwin_maxsz = size; | ||
838 | options.iopt_size = 128; | ||
839 | options.smatch_cfg = XD3_SMATCH_SLOW; | ||
840 | options.size_known = false; | ||
841 | |||
842 | Block block1; | ||
843 | InMemoryEncodeDecode(spec0, spec1, &block1, options); | ||
844 | Delta delta1(block1); | ||
845 | // Allow one missed window (e.g., hash collisions) | ||
846 | added_01 += delta1.AddedBytes(); | ||
847 | |||
848 | Block block2; | ||
849 | InMemoryEncodeDecode(spec1, spec0, &block2, options); | ||
850 | Delta delta2(block2); | ||
851 | // Allow one missed window (e.g., hash collisions) | ||
852 | added_10 += delta2.AddedBytes(); | ||
853 | |||
854 | Block block3; | ||
855 | Block block4; | ||
856 | EncodeDecodeAPI(spec0, spec1, &block3, options); | ||
857 | EncodeDecodeAPI(spec1, spec0, &block4, options); | ||
858 | } | ||
859 | // Average less than 0.5 misses (of length clen) per iteration. | ||
860 | CHECK_GE(clen * iters / 2, added_01); | ||
861 | CHECK_GE(clen * iters / 2, added_10); | ||
852 | } | 862 | } |
853 | 863 | ||
854 | void TestCopyFromEnd() { | 864 | void TestCopyFromEnd() { |
@@ -857,46 +867,53 @@ void TestCopyFromEnd() { | |||
857 | const int size = 4096; | 867 | const int size = 4096; |
858 | const int clen = 16; | 868 | const int clen = 16; |
859 | const int nmov = (size / 2) / clen; | 869 | const int nmov = (size / 2) / clen; |
860 | MTRandom rand; | 870 | const int iters = 16; |
861 | FileSpec spec0(&rand); | 871 | uint32_t added_01 = 0; |
862 | ChangeList cl; | 872 | uint32_t added_10 = 0; |
873 | for (int i = 1; i <= iters; i++) { | ||
874 | MTRandom rand(MTRandom::TEST_SEED1 * i); | ||
875 | FileSpec spec0(&rand); | ||
876 | ChangeList cl; | ||
863 | 877 | ||
864 | spec0.GenerateFixedSize(size); | 878 | spec0.GenerateFixedSize(size); |
865 | 879 | ||
866 | cl.push_back(Change(Change::MODIFY, 2012, 2048)); | 880 | cl.push_back(Change(Change::MODIFY, 2012, 2048)); |
867 | 881 | ||
868 | for (int j = 0; j < nmov; j += 2) | 882 | for (int j = 0; j < nmov; j += 2) |
869 | { | 883 | { |
870 | cl.push_back(Change(Change::MOVE, | 884 | cl.push_back(Change(Change::MOVE, |
871 | clen, (j + 1) * clen, j * clen)); | 885 | clen, (j + 1) * clen, j * clen)); |
872 | } | 886 | } |
873 | 887 | ||
874 | cl.push_back(Change(Change::COPYOVER, 28, 4068, 3000)); | 888 | cl.push_back(Change(Change::COPYOVER, 28, 4068, 3000)); |
875 | cl.push_back(Change(Change::COPYOVER, 30, 4066, 3100)); | 889 | cl.push_back(Change(Change::COPYOVER, 30, 4066, 3100)); |
876 | cl.push_back(Change(Change::COPYOVER, 32, 4064, 3200)); | 890 | cl.push_back(Change(Change::COPYOVER, 32, 4064, 3200)); |
877 | 891 | ||
878 | FileSpec spec1(&rand); | 892 | FileSpec spec1(&rand); |
879 | spec0.ModifyTo(ChangeListMutator(cl), &spec1); | 893 | spec0.ModifyTo(ChangeListMutator(cl), &spec1); |
880 | 894 | ||
881 | Options options; | 895 | Options options; |
882 | options.encode_srcwin_maxsz = size; | 896 | options.encode_srcwin_maxsz = size; |
883 | options.iopt_size = 128; | 897 | options.iopt_size = 128; |
884 | options.smatch_cfg = XD3_SMATCH_SLOW; | 898 | options.smatch_cfg = XD3_SMATCH_SLOW; |
885 | 899 | ||
886 | Block block1; | 900 | Block block1; |
887 | InMemoryEncodeDecode(spec0, spec1, &block1, options); | 901 | InMemoryEncodeDecode(spec0, spec1, &block1, options); |
888 | Delta delta1(block1); | 902 | Delta delta1(block1); |
889 | CHECK_GE(2000, delta1.AddedBytes()); | 903 | added_01 += delta1.AddedBytes(); |
890 | 904 | ||
891 | Block block2; | 905 | Block block2; |
892 | InMemoryEncodeDecode(spec1, spec0, &block2, options); | 906 | InMemoryEncodeDecode(spec1, spec0, &block2, options); |
893 | Delta delta2(block2); | 907 | Delta delta2(block2); |
894 | CHECK_LE(2000, delta2.AddedBytes()); | 908 | added_10 += delta2.AddedBytes(); |
895 | 909 | ||
896 | Block block3; | 910 | Block block3; |
897 | Block block4; | 911 | Block block4; |
898 | EncodeDecodeAPI(spec0, spec1, &block3, options); | 912 | EncodeDecodeAPI(spec0, spec1, &block3, options); |
899 | EncodeDecodeAPI(spec1, spec0, &block4, options); | 913 | EncodeDecodeAPI(spec1, spec0, &block4, options); |
914 | } | ||
915 | CHECK_GE(2000 * iters, added_01); | ||
916 | CHECK_LE(2000 * iters, added_10); | ||
900 | } | 917 | } |
901 | 918 | ||
902 | void TestHalfBlockCopy() { | 919 | void TestHalfBlockCopy() { |
diff --git a/xdelta3/xdelta3.c b/xdelta3/xdelta3.c index c2c8d3e..78a331e 100644 --- a/xdelta3/xdelta3.c +++ b/xdelta3/xdelta3.c | |||
@@ -3697,7 +3697,7 @@ xd3_encode_init (xd3_stream *stream, int full_init) | |||
3697 | * identical or short inputs require no table allocation. */ | 3697 | * identical or short inputs require no table allocation. */ |
3698 | if (large_comp) | 3698 | if (large_comp) |
3699 | { | 3699 | { |
3700 | usize_t hash_values = (2 * stream->src->max_winsize) / | 3700 | usize_t hash_values = stream->src->max_winsize / |
3701 | stream->smatcher.large_step; | 3701 | stream->smatcher.large_step; |
3702 | 3702 | ||
3703 | xd3_size_hashtable (stream, | 3703 | xd3_size_hashtable (stream, |