Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

It now does comparisons of SPDY3 and SPDY4 compressors.

Thusfar, the results are encouraging.
Using the window size used by Chrome, the SPDY4 compressor has equivalent compression with 1/3rd the CPU cost.
  • Loading branch information...
commit 5f75bce5c098d6277f71939c352c6aceb8414f56 1 parent 99d61bb
Roberto Peon authored
View
2  example_code/Makefile
@@ -32,7 +32,7 @@ clean:
$(CXX) $(CXXFLAGS) $< -c -o $@
spdy4_headers_sample: spdy4_headers_sample.o spdy4_headers_codec.o header_freq_tables.o
- $(CXX) $(CXXFLAGS) $^ -o $@ -lrt
+ $(CXX) $(CXXFLAGS) $^ -o $@ -lrt -lz
bit_bucket_test: bit_bucket_test.o
$(CXX) $(CXXFLAGS) $^ -o $@
View
187 example_code/spdy3_dictionary.h
@@ -0,0 +1,187 @@
+#ifndef SPDY3_DICTIONARY_H__
+#define SPDY3_DICTIONARY_H__
+
+
+const unsigned char SPDY_dictionary_txt[] = {
+ 0x00, 0x00, 0x00, 0x07, 0x6f, 0x70, 0x74, 0x69, // - - - - o p t i
+ 0x6f, 0x6e, 0x73, 0x00, 0x00, 0x00, 0x04, 0x68, // o n s - - - - h
+ 0x65, 0x61, 0x64, 0x00, 0x00, 0x00, 0x04, 0x70, // e a d - - - - p
+ 0x6f, 0x73, 0x74, 0x00, 0x00, 0x00, 0x03, 0x70, // o s t - - - - p
+ 0x75, 0x74, 0x00, 0x00, 0x00, 0x06, 0x64, 0x65, // u t - - - - d e
+ 0x6c, 0x65, 0x74, 0x65, 0x00, 0x00, 0x00, 0x05, // l e t e - - - -
+ 0x74, 0x72, 0x61, 0x63, 0x65, 0x00, 0x00, 0x00, // t r a c e - - -
+ 0x06, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x00, // - a c c e p t -
+ 0x00, 0x00, 0x0e, 0x61, 0x63, 0x63, 0x65, 0x70, // - - - a c c e p
+ 0x74, 0x2d, 0x63, 0x68, 0x61, 0x72, 0x73, 0x65, // t - c h a r s e
+ 0x74, 0x00, 0x00, 0x00, 0x0f, 0x61, 0x63, 0x63, // t - - - - a c c
+ 0x65, 0x70, 0x74, 0x2d, 0x65, 0x6e, 0x63, 0x6f, // e p t - e n c o
+ 0x64, 0x69, 0x6e, 0x67, 0x00, 0x00, 0x00, 0x0f, // d i n g - - - -
+ 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x2d, 0x6c, // a c c e p t - l
+ 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x00, // a n g u a g e -
+ 0x00, 0x00, 0x0d, 0x61, 0x63, 0x63, 0x65, 0x70, // - - - a c c e p
+ 0x74, 0x2d, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x73, // t - r a n g e s
+ 0x00, 0x00, 0x00, 0x03, 0x61, 0x67, 0x65, 0x00, // - - - - a g e -
+ 0x00, 0x00, 0x05, 0x61, 0x6c, 0x6c, 0x6f, 0x77, // - - - a l l o w
+ 0x00, 0x00, 0x00, 0x0d, 0x61, 0x75, 0x74, 0x68, // - - - - a u t h
+ 0x6f, 0x72, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, // o r i z a t i o
+ 0x6e, 0x00, 0x00, 0x00, 0x0d, 0x63, 0x61, 0x63, // n - - - - c a c
+ 0x68, 0x65, 0x2d, 0x63, 0x6f, 0x6e, 0x74, 0x72, // h e - c o n t r
+ 0x6f, 0x6c, 0x00, 0x00, 0x00, 0x0a, 0x63, 0x6f, // o l - - - - c o
+ 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, // n n e c t i o n
+ 0x00, 0x00, 0x00, 0x0c, 0x63, 0x6f, 0x6e, 0x74, // - - - - c o n t
+ 0x65, 0x6e, 0x74, 0x2d, 0x62, 0x61, 0x73, 0x65, // e n t - b a s e
+ 0x00, 0x00, 0x00, 0x10, 0x63, 0x6f, 0x6e, 0x74, // - - - - c o n t
+ 0x65, 0x6e, 0x74, 0x2d, 0x65, 0x6e, 0x63, 0x6f, // e n t - e n c o
+ 0x64, 0x69, 0x6e, 0x67, 0x00, 0x00, 0x00, 0x10, // d i n g - - - -
+ 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, // c o n t e n t -
+ 0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, // l a n g u a g e
+ 0x00, 0x00, 0x00, 0x0e, 0x63, 0x6f, 0x6e, 0x74, // - - - - c o n t
+ 0x65, 0x6e, 0x74, 0x2d, 0x6c, 0x65, 0x6e, 0x67, // e n t - l e n g
+ 0x74, 0x68, 0x00, 0x00, 0x00, 0x10, 0x63, 0x6f, // t h - - - - c o
+ 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x6c, 0x6f, // n t e n t - l o
+ 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, // c a t i o n - -
+ 0x00, 0x0b, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, // - - c o n t e n
+ 0x74, 0x2d, 0x6d, 0x64, 0x35, 0x00, 0x00, 0x00, // t - m d 5 - - -
+ 0x0d, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, // - c o n t e n t
+ 0x2d, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x00, 0x00, // - r a n g e - -
+ 0x00, 0x0c, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, // - - c o n t e n
+ 0x74, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x00, 0x00, // t - t y p e - -
+ 0x00, 0x04, 0x64, 0x61, 0x74, 0x65, 0x00, 0x00, // - - d a t e - -
+ 0x00, 0x04, 0x65, 0x74, 0x61, 0x67, 0x00, 0x00, // - - e t a g - -
+ 0x00, 0x06, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, // - - e x p e c t
+ 0x00, 0x00, 0x00, 0x07, 0x65, 0x78, 0x70, 0x69, // - - - - e x p i
+ 0x72, 0x65, 0x73, 0x00, 0x00, 0x00, 0x04, 0x66, // r e s - - - - f
+ 0x72, 0x6f, 0x6d, 0x00, 0x00, 0x00, 0x04, 0x68, // r o m - - - - h
+ 0x6f, 0x73, 0x74, 0x00, 0x00, 0x00, 0x08, 0x69, // o s t - - - - i
+ 0x66, 0x2d, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x00, // f - m a t c h -
+ 0x00, 0x00, 0x11, 0x69, 0x66, 0x2d, 0x6d, 0x6f, // - - - i f - m o
+ 0x64, 0x69, 0x66, 0x69, 0x65, 0x64, 0x2d, 0x73, // d i f i e d - s
+ 0x69, 0x6e, 0x63, 0x65, 0x00, 0x00, 0x00, 0x0d, // i n c e - - - -
+ 0x69, 0x66, 0x2d, 0x6e, 0x6f, 0x6e, 0x65, 0x2d, // i f - n o n e -
+ 0x6d, 0x61, 0x74, 0x63, 0x68, 0x00, 0x00, 0x00, // m a t c h - - -
+ 0x08, 0x69, 0x66, 0x2d, 0x72, 0x61, 0x6e, 0x67, // - i f - r a n g
+ 0x65, 0x00, 0x00, 0x00, 0x13, 0x69, 0x66, 0x2d, // e - - - - i f -
+ 0x75, 0x6e, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, // u n m o d i f i
+ 0x65, 0x64, 0x2d, 0x73, 0x69, 0x6e, 0x63, 0x65, // e d - s i n c e
+ 0x00, 0x00, 0x00, 0x0d, 0x6c, 0x61, 0x73, 0x74, // - - - - l a s t
+ 0x2d, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x65, // - m o d i f i e
+ 0x64, 0x00, 0x00, 0x00, 0x08, 0x6c, 0x6f, 0x63, // d - - - - l o c
+ 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x00, // a t i o n - - -
+ 0x0c, 0x6d, 0x61, 0x78, 0x2d, 0x66, 0x6f, 0x72, // - m a x - f o r
+ 0x77, 0x61, 0x72, 0x64, 0x73, 0x00, 0x00, 0x00, // w a r d s - - -
+ 0x06, 0x70, 0x72, 0x61, 0x67, 0x6d, 0x61, 0x00, // - p r a g m a -
+ 0x00, 0x00, 0x12, 0x70, 0x72, 0x6f, 0x78, 0x79, // - - - p r o x y
+ 0x2d, 0x61, 0x75, 0x74, 0x68, 0x65, 0x6e, 0x74, // - a u t h e n t
+ 0x69, 0x63, 0x61, 0x74, 0x65, 0x00, 0x00, 0x00, // i c a t e - - -
+ 0x13, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2d, 0x61, // - p r o x y - a
+ 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x61, // u t h o r i z a
+ 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x00, 0x05, // t i o n - - - -
+ 0x72, 0x61, 0x6e, 0x67, 0x65, 0x00, 0x00, 0x00, // r a n g e - - -
+ 0x07, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x72, // - r e f e r e r
+ 0x00, 0x00, 0x00, 0x0b, 0x72, 0x65, 0x74, 0x72, // - - - - r e t r
+ 0x79, 0x2d, 0x61, 0x66, 0x74, 0x65, 0x72, 0x00, // y - a f t e r -
+ 0x00, 0x00, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, // - - - s e r v e
+ 0x72, 0x00, 0x00, 0x00, 0x02, 0x74, 0x65, 0x00, // r - - - - t e -
+ 0x00, 0x00, 0x07, 0x74, 0x72, 0x61, 0x69, 0x6c, // - - - t r a i l
+ 0x65, 0x72, 0x00, 0x00, 0x00, 0x11, 0x74, 0x72, // e r - - - - t r
+ 0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 0x2d, 0x65, // a n s f e r - e
+ 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x00, // n c o d i n g -
+ 0x00, 0x00, 0x07, 0x75, 0x70, 0x67, 0x72, 0x61, // - - - u p g r a
+ 0x64, 0x65, 0x00, 0x00, 0x00, 0x0a, 0x75, 0x73, // d e - - - - u s
+ 0x65, 0x72, 0x2d, 0x61, 0x67, 0x65, 0x6e, 0x74, // e r - a g e n t
+ 0x00, 0x00, 0x00, 0x04, 0x76, 0x61, 0x72, 0x79, // - - - - v a r y
+ 0x00, 0x00, 0x00, 0x03, 0x76, 0x69, 0x61, 0x00, // - - - - v i a -
+ 0x00, 0x00, 0x07, 0x77, 0x61, 0x72, 0x6e, 0x69, // - - - w a r n i
+ 0x6e, 0x67, 0x00, 0x00, 0x00, 0x10, 0x77, 0x77, // n g - - - - w w
+ 0x77, 0x2d, 0x61, 0x75, 0x74, 0x68, 0x65, 0x6e, // w - a u t h e n
+ 0x74, 0x69, 0x63, 0x61, 0x74, 0x65, 0x00, 0x00, // t i c a t e - -
+ 0x00, 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, // - - m e t h o d
+ 0x00, 0x00, 0x00, 0x03, 0x67, 0x65, 0x74, 0x00, // - - - - g e t -
+ 0x00, 0x00, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, // - - - s t a t u
+ 0x73, 0x00, 0x00, 0x00, 0x06, 0x32, 0x30, 0x30, // s - - - - 2 0 0
+ 0x20, 0x4f, 0x4b, 0x00, 0x00, 0x00, 0x07, 0x76, // - O K - - - - v
+ 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x00, 0x00, // e r s i o n - -
+ 0x00, 0x08, 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, // - - H T T P - 1
+ 0x2e, 0x31, 0x00, 0x00, 0x00, 0x03, 0x75, 0x72, // - 1 - - - - u r
+ 0x6c, 0x00, 0x00, 0x00, 0x06, 0x70, 0x75, 0x62, // l - - - - p u b
+ 0x6c, 0x69, 0x63, 0x00, 0x00, 0x00, 0x0a, 0x73, // l i c - - - - s
+ 0x65, 0x74, 0x2d, 0x63, 0x6f, 0x6f, 0x6b, 0x69, // e t - c o o k i
+ 0x65, 0x00, 0x00, 0x00, 0x0a, 0x6b, 0x65, 0x65, // e - - - - k e e
+ 0x70, 0x2d, 0x61, 0x6c, 0x69, 0x76, 0x65, 0x00, // p - a l i v e -
+ 0x00, 0x00, 0x06, 0x6f, 0x72, 0x69, 0x67, 0x69, // - - - o r i g i
+ 0x6e, 0x31, 0x30, 0x30, 0x31, 0x30, 0x31, 0x32, // n 1 0 0 1 0 1 2
+ 0x30, 0x31, 0x32, 0x30, 0x32, 0x32, 0x30, 0x35, // 0 1 2 0 2 2 0 5
+ 0x32, 0x30, 0x36, 0x33, 0x30, 0x30, 0x33, 0x30, // 2 0 6 3 0 0 3 0
+ 0x32, 0x33, 0x30, 0x33, 0x33, 0x30, 0x34, 0x33, // 2 3 0 3 3 0 4 3
+ 0x30, 0x35, 0x33, 0x30, 0x36, 0x33, 0x30, 0x37, // 0 5 3 0 6 3 0 7
+ 0x34, 0x30, 0x32, 0x34, 0x30, 0x35, 0x34, 0x30, // 4 0 2 4 0 5 4 0
+ 0x36, 0x34, 0x30, 0x37, 0x34, 0x30, 0x38, 0x34, // 6 4 0 7 4 0 8 4
+ 0x30, 0x39, 0x34, 0x31, 0x30, 0x34, 0x31, 0x31, // 0 9 4 1 0 4 1 1
+ 0x34, 0x31, 0x32, 0x34, 0x31, 0x33, 0x34, 0x31, // 4 1 2 4 1 3 4 1
+ 0x34, 0x34, 0x31, 0x35, 0x34, 0x31, 0x36, 0x34, // 4 4 1 5 4 1 6 4
+ 0x31, 0x37, 0x35, 0x30, 0x32, 0x35, 0x30, 0x34, // 1 7 5 0 2 5 0 4
+ 0x35, 0x30, 0x35, 0x32, 0x30, 0x33, 0x20, 0x4e, // 5 0 5 2 0 3 - N
+ 0x6f, 0x6e, 0x2d, 0x41, 0x75, 0x74, 0x68, 0x6f, // o n - A u t h o
+ 0x72, 0x69, 0x74, 0x61, 0x74, 0x69, 0x76, 0x65, // r i t a t i v e
+ 0x20, 0x49, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, // - I n f o r m a
+ 0x74, 0x69, 0x6f, 0x6e, 0x32, 0x30, 0x34, 0x20, // t i o n 2 0 4 -
+ 0x4e, 0x6f, 0x20, 0x43, 0x6f, 0x6e, 0x74, 0x65, // N o - C o n t e
+ 0x6e, 0x74, 0x33, 0x30, 0x31, 0x20, 0x4d, 0x6f, // n t 3 0 1 - M o
+ 0x76, 0x65, 0x64, 0x20, 0x50, 0x65, 0x72, 0x6d, // v e d - P e r m
+ 0x61, 0x6e, 0x65, 0x6e, 0x74, 0x6c, 0x79, 0x34, // a n e n t l y 4
+ 0x30, 0x30, 0x20, 0x42, 0x61, 0x64, 0x20, 0x52, // 0 0 - B a d - R
+ 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x34, 0x30, // e q u e s t 4 0
+ 0x31, 0x20, 0x55, 0x6e, 0x61, 0x75, 0x74, 0x68, // 1 - U n a u t h
+ 0x6f, 0x72, 0x69, 0x7a, 0x65, 0x64, 0x34, 0x30, // o r i z e d 4 0
+ 0x33, 0x20, 0x46, 0x6f, 0x72, 0x62, 0x69, 0x64, // 3 - F o r b i d
+ 0x64, 0x65, 0x6e, 0x34, 0x30, 0x34, 0x20, 0x4e, // d e n 4 0 4 - N
+ 0x6f, 0x74, 0x20, 0x46, 0x6f, 0x75, 0x6e, 0x64, // o t - F o u n d
+ 0x35, 0x30, 0x30, 0x20, 0x49, 0x6e, 0x74, 0x65, // 5 0 0 - I n t e
+ 0x72, 0x6e, 0x61, 0x6c, 0x20, 0x53, 0x65, 0x72, // r n a l - S e r
+ 0x76, 0x65, 0x72, 0x20, 0x45, 0x72, 0x72, 0x6f, // v e r - E r r o
+ 0x72, 0x35, 0x30, 0x31, 0x20, 0x4e, 0x6f, 0x74, // r 5 0 1 - N o t
+ 0x20, 0x49, 0x6d, 0x70, 0x6c, 0x65, 0x6d, 0x65, // - I m p l e m e
+ 0x6e, 0x74, 0x65, 0x64, 0x35, 0x30, 0x33, 0x20, // n t e d 5 0 3 -
+ 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x20, // S e r v i c e -
+ 0x55, 0x6e, 0x61, 0x76, 0x61, 0x69, 0x6c, 0x61, // U n a v a i l a
+ 0x62, 0x6c, 0x65, 0x4a, 0x61, 0x6e, 0x20, 0x46, // b l e J a n - F
+ 0x65, 0x62, 0x20, 0x4d, 0x61, 0x72, 0x20, 0x41, // e b - M a r - A
+ 0x70, 0x72, 0x20, 0x4d, 0x61, 0x79, 0x20, 0x4a, // p r - M a y - J
+ 0x75, 0x6e, 0x20, 0x4a, 0x75, 0x6c, 0x20, 0x41, // u n - J u l - A
+ 0x75, 0x67, 0x20, 0x53, 0x65, 0x70, 0x74, 0x20, // u g - S e p t -
+ 0x4f, 0x63, 0x74, 0x20, 0x4e, 0x6f, 0x76, 0x20, // O c t - N o v -
+ 0x44, 0x65, 0x63, 0x20, 0x30, 0x30, 0x3a, 0x30, // D e c - 0 0 - 0
+ 0x30, 0x3a, 0x30, 0x30, 0x20, 0x4d, 0x6f, 0x6e, // 0 - 0 0 - M o n
+ 0x2c, 0x20, 0x54, 0x75, 0x65, 0x2c, 0x20, 0x57, // - - T u e - - W
+ 0x65, 0x64, 0x2c, 0x20, 0x54, 0x68, 0x75, 0x2c, // e d - - T h u -
+ 0x20, 0x46, 0x72, 0x69, 0x2c, 0x20, 0x53, 0x61, // - F r i - - S a
+ 0x74, 0x2c, 0x20, 0x53, 0x75, 0x6e, 0x2c, 0x20, // t - - S u n - -
+ 0x47, 0x4d, 0x54, 0x63, 0x68, 0x75, 0x6e, 0x6b, // G M T c h u n k
+ 0x65, 0x64, 0x2c, 0x74, 0x65, 0x78, 0x74, 0x2f, // e d - t e x t -
+ 0x68, 0x74, 0x6d, 0x6c, 0x2c, 0x69, 0x6d, 0x61, // h t m l - i m a
+ 0x67, 0x65, 0x2f, 0x70, 0x6e, 0x67, 0x2c, 0x69, // g e - p n g - i
+ 0x6d, 0x61, 0x67, 0x65, 0x2f, 0x6a, 0x70, 0x67, // m a g e - j p g
+ 0x2c, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2f, 0x67, // - i m a g e - g
+ 0x69, 0x66, 0x2c, 0x61, 0x70, 0x70, 0x6c, 0x69, // i f - a p p l i
+ 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x78, // c a t i o n - x
+ 0x6d, 0x6c, 0x2c, 0x61, 0x70, 0x70, 0x6c, 0x69, // m l - a p p l i
+ 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x78, // c a t i o n - x
+ 0x68, 0x74, 0x6d, 0x6c, 0x2b, 0x78, 0x6d, 0x6c, // h t m l - x m l
+ 0x2c, 0x74, 0x65, 0x78, 0x74, 0x2f, 0x70, 0x6c, // - t e x t - p l
+ 0x61, 0x69, 0x6e, 0x2c, 0x74, 0x65, 0x78, 0x74, // a i n - t e x t
+ 0x2f, 0x6a, 0x61, 0x76, 0x61, 0x73, 0x63, 0x72, // - j a v a s c r
+ 0x69, 0x70, 0x74, 0x2c, 0x70, 0x75, 0x62, 0x6c, // i p t - p u b l
+ 0x69, 0x63, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, // i c p r i v a t
+ 0x65, 0x6d, 0x61, 0x78, 0x2d, 0x61, 0x67, 0x65, // e m a x - a g e
+ 0x3d, 0x67, 0x7a, 0x69, 0x70, 0x2c, 0x64, 0x65, // - g z i p - d e
+ 0x66, 0x6c, 0x61, 0x74, 0x65, 0x2c, 0x73, 0x64, // f l a t e - s d
+ 0x63, 0x68, 0x63, 0x68, 0x61, 0x72, 0x73, 0x65, // c h c h a r s e
+ 0x74, 0x3d, 0x75, 0x74, 0x66, 0x2d, 0x38, 0x63, // t - u t f - 8 c
+ 0x68, 0x61, 0x72, 0x73, 0x65, 0x74, 0x3d, 0x69, // h a r s e t - i
+ 0x73, 0x6f, 0x2d, 0x38, 0x38, 0x35, 0x39, 0x2d, // s o - 8 8 5 9 -
+ 0x31, 0x2c, 0x75, 0x74, 0x66, 0x2d, 0x2c, 0x2a, // 1 - u t f - - -
+ 0x2c, 0x65, 0x6e, 0x71, 0x3d, 0x30, 0x2e // - e n q - 0 -
+};
+
+
+#endif
View
14 example_code/spdy4_headers_codec.cc
@@ -619,13 +619,13 @@ DEBUG_PRINT(
} else if (lc.HasKey()) {
instrs->clones.push_back(CloneOp(lc, &val));
} else {
- if (key != ":path") {
+ //if (key != ":path") {
instrs->kvstos.push_back(KVStoOp(&key, &val));
- } else {
- // we really want a clone that doesn't store the val
- // but I have yet to make that up...
- instrs->erefs.push_back(ERefOp(&key, &val));
- }
+ //} else {
+ // // we really want a clone that doesn't store the val
+ // // but I have yet to make that up...
+ // instrs->erefs.push_back(ERefOp(&key, &val));
+ //}
}
}
@@ -1089,7 +1089,7 @@ class InlineSerialization :
//if (huff) {
- is->huff->Encode(&is->bb, str, true);
+ is->huff->Encode(&is->bb, str,true);
is->os->WriteBytes(is->bb.BytesBegin(), is->bb.BytesEnd());
is->bb.Clear();
// } else {
View
211 example_code/spdy4_headers_sample.cc
@@ -1,15 +1,26 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+
#include <unistd.h>
#include <fcntl.h>
#include <time.h>
+#include <zlib.h>
+
+#include <memory>
+#include <cstring>
+
#include "bit_bucket.h"
#include "header_freq_tables.h"
#include "huffman.h"
#include "trivial_http_parse.h"
#include "spdy4_headers_codec.h"
+#include "spdy3_dictionary.h"
+
+using std::unique_ptr;
+using std::vector;
+using std::memset;
int ParseHarFiles(int n_files, char** files,
vector<HeaderFrame>* requests,
@@ -84,8 +95,8 @@ class SimpleTimer {
size_t delta_nsec;
size_t delta_sec;
if (ts_end.tv_nsec < ts_start.tv_nsec) {
- delta_nsec = 1000000000 + ts_end.tv_nsec - ts_start.tv_nsec;
- delta_sec = ts_end.tv_sec - (ts_start.tv_sec - 1);
+ delta_nsec = 1000000000 - (ts_start.tv_nsec - ts_end.tv_nsec);
+ delta_sec = (ts_end.tv_sec - 1) - ts_start.tv_sec;
} else {
delta_nsec = ts_end.tv_nsec - ts_start.tv_nsec;
delta_sec = ts_end.tv_sec - ts_start.tv_sec;
@@ -105,25 +116,162 @@ void OutputHeaderFrame(const HeaderFrame& hf) {
}
}
-pair<size_t,double> DoSPDY3CoDec(size_t iterations, const vector<HeaderFrame>& frames) {
+struct Stats {
+ size_t compressed_size;
+ double elapsed_time;
+ size_t iterations;
+ Stats() : compressed_size(0), elapsed_time(0), iterations(0) {}
+ Stats(size_t cs, double et, size_t it) :
+ compressed_size(cs), elapsed_time(et), iterations(it) {}
+};
+
+#define SPDY3
+#ifdef SPDY3
+static const int kCompressorLevel = 9;
+static const int kCompressorWindowSizeInBits = 11;
+static const int kCompressorMemLevel = 1;
+
+class SPDY3Formatter {
+ unique_ptr<z_stream> header_compressor_;
+ vector<char> output_buffer;
+ vector<char> to_be_compressed;
+ size_t output_capacity;
+ public:
+
+ SPDY3Formatter() : output_capacity(0) {
+ InitHeaderCompressor();
+ }
+
+ void ResizeOutput(vector<char>* out, size_t required_extra_capacity) {
+ out->resize(out->size() + required_extra_capacity);
+ }
+
+
+ void InitHeaderCompressor() {
+ header_compressor_.reset(new z_stream);
+ memset(header_compressor_.get(), 0, sizeof(z_stream));
+ int success = deflateInit2(header_compressor_.get(),
+ kCompressorLevel,
+ Z_DEFLATED,
+ kCompressorWindowSizeInBits,
+ kCompressorMemLevel,
+ Z_DEFAULT_STRATEGY);
+ if (success == Z_OK) {
+ const unsigned char* dictionary = SPDY_dictionary_txt;
+ success = deflateSetDictionary(header_compressor_.get(),
+ reinterpret_cast<const Bytef*>(dictionary),
+ sizeof(SPDY_dictionary_txt));
+ }
+ if (success != Z_OK) {
+ cerr << "deflateSetDictionary failure: " << success;
+ header_compressor_.reset(NULL);
+ abort();
+ }
+ }
+
+ void Compress(vector<char>* out, const vector<char>& to_be_compressed) {
+ z_stream* compressor = header_compressor_.get();
+ assert(compressor);
+
+ int payload_length = to_be_compressed.size();
+ char* payload = const_cast<char*>(&(to_be_compressed[0]));
+ int compressed_max_size = deflateBound(compressor, payload_length);
+ size_t output_prev_size = out->size();
+ out->resize(out->size() + compressed_max_size);
+ char* output_ptr = &((*out)[output_prev_size]);
+
+
+ compressor->next_in = reinterpret_cast<Bytef*>(payload);
+ compressor->avail_in = payload_length;
+ compressor->next_out = reinterpret_cast<Bytef*>(output_ptr);
+ compressor->avail_out = compressed_max_size;
+
+ int rv = deflate(compressor, Z_SYNC_FLUSH);
+ if (rv != Z_OK) { // How can we know that it compressed everything?
+ // This shouldn't happen, right?
+ cerr << "deflate failure: " << rv;
+ abort();
+ }
+
+ out->resize(out->size() - compressor->avail_out);
+ }
+
+ static void OverwriteInt24(vector<char>* out,
+ size_t pos,
+ uint32_t val) {
+ (*out)[pos+0] = (val >> 16 & 255u);
+ (*out)[pos+1] = (val >> 8 & 255u);
+ (*out)[pos+2] = (val >> 0& 255u);
+ }
+
+ static void AppendInt32(vector<char>* out, uint32_t val) {
+ out->push_back((uint8_t)(255u & val >> 24));
+ out->push_back((uint8_t)(255u & val >> 16));
+ out->push_back((uint8_t)(255u & val >> 8));
+ out->push_back((uint8_t)(255u & val >> 0));
+ }
+
+ static void AppendInt24(vector<char>* out, uint32_t val) {
+ out->push_back((uint8_t)(255u & val >> 16));
+ out->push_back((uint8_t)(255u & val >> 8));
+ out->push_back((uint8_t)(255u & val >> 0));
+ }
+
+ void FormatHeaderBlock(vector<char>* tbc,
+ const HeaderFrame& frame) {
+ AppendInt32(tbc, frame.size());
+ for (size_t i = 0; i < frame.size(); ++i) {
+ AppendInt32(tbc, frame[i].key.size());
+ tbc->insert(tbc->end(), frame[i].key.begin(), frame[i].key.end());
+ AppendInt32(tbc, frame[i].val.size());
+ tbc->insert(tbc->end(), frame[i].val.begin(), frame[i].val.end());
+ }
+ }
+
+ void FormatHeaders(vector<char>* out, const HeaderFrame& frame) {
+ out->push_back(0x1u<<7); // control-frame
+ out->push_back(0x3u); // version 3
+ out->push_back(0); // type
+ out->push_back(8u); // ..
+ out->push_back(0); // flags
+ size_t length_pin = out->size(); // we'll ahve to overwrite this later.
+ AppendInt24(out, 0); // length, which is bogus here.
+ AppendInt32(out, 1); // stream_id
+ FormatHeaderBlock(&to_be_compressed, frame);
+ Compress(out, to_be_compressed);
+ to_be_compressed.clear();
+ OverwriteInt24(out, length_pin, out->size() - length_pin);
+ }
+};
+
+
+Stats DoSPDY3CoDec(double time_to_iterate,
+ const vector<HeaderFrame>& frames) {
+ SPDY3Formatter spdy3_formatter;
size_t compressed_size = 0;
- double d = 0;
SimpleTimer timer;
timer.Start();
- for (size_t i = 0; i < iterations; ++i) {
+ size_t iterations = 0;
+ while (timer.ElapsedTime() < time_to_iterate) {
+ ++iterations;
for (size_t j = 0; j < frames.size(); ++j) {
- for (size_t k = 0; k < frames[j].size(); ++k) {
- compressed_size += frames[j][k].key.size();
- compressed_size += frames[j][k].val.size();
- d += i+j+k;
- }
+ vector<char> output;
+ const HeaderFrame& request = frames[j];
+ size_t prev_size = output.size();
+ spdy3_formatter.FormatHeaders(&output, request);
+ size_t framesize = output.size() - prev_size;
+ compressed_size += framesize;
}
}
timer.Stop();
- return make_pair(compressed_size, timer.ElapsedTime());;
+ return Stats(compressed_size, timer.ElapsedTime(), iterations);
}
+#endif
+
-pair<size_t,double> DoSPDY4CoDec(size_t desired_iterations, const vector<HeaderFrame>& frames) {
+
+Stats DoSPDY4CoDec(double time_to_iterate,
+ const vector<HeaderFrame>& frames) {
size_t compressed_size = 0;
const int header_group = 1;
const int stream_id = 1;
@@ -132,10 +280,12 @@ pair<size_t,double> DoSPDY4CoDec(size_t desired_iterations, const vector<HeaderF
SimpleTimer timer;
timer.Start();
- for (size_t iterations = 0; iterations < desired_iterations; ++iterations) {
- for (unsigned int i = 0; i < frames.size(); ++i) {
+ size_t iterations = 0;
+ while (timer.ElapsedTime() < time_to_iterate) {
+ ++iterations;
+ for (unsigned int j = 0; j < frames.size(); ++j) {
OutputStream os;
- const HeaderFrame& request = frames[i];
+ const HeaderFrame& request = frames[j];
#ifdef DEBUG
cout << "++++++++++++++++++++++\n";
OutputHeaderFrame(request);
@@ -161,17 +311,18 @@ pair<size_t,double> DoSPDY4CoDec(size_t desired_iterations, const vector<HeaderF
}
}
timer.Stop();
- return make_pair(compressed_size, timer.ElapsedTime());
+ return Stats(compressed_size, timer.ElapsedTime(), iterations);
}
void PrintSummary(const string& protocol_name,
- pair<size_t, double> stats,
- size_t iterations,
+ Stats stats,
size_t uncompressed_size,
size_t header_count) {
- double secs = stats.second;
- size_t total_compressed_size = stats.first;
- double compression_ratio = (double)total_compressed_size / (double) uncompressed_size;
+ double secs = stats.elapsed_time;
+ size_t total_compressed_size = stats.compressed_size;
+ size_t iterations = stats.iterations;
+ double compression_ratio = ((double)total_compressed_size /
+ (double) uncompressed_size);
compression_ratio /= iterations;
cout << "\n\n";
cout << "################# " << protocol_name << " ################\n";
@@ -181,7 +332,9 @@ void PrintSummary(const string& protocol_name,
<< " or " << (header_count * iterations) / secs << " headers/sec"
<< " or " << (uncompressed_size * iterations) / secs << " bytes/sec"
<< "\n";
- cout << "Compression ratio: " << compression_ratio << "\n";
+ cout << "Compression ratio: " << compression_ratio << "\n"
+ << "Uncompressed bytes: " << (uncompressed_size * iterations) << "\n"
+ << " compressed bytes: " << total_compressed_size << "\n";
}
int main(int argc, char** argv) {
@@ -198,12 +351,16 @@ int main(int argc, char** argv) {
request_header_bytes += requests[i][j].val.size();
}
}
- const size_t iterations = 100;
+ const double time_to_iterate = 4.0;
- pair<size_t, double> spdy3_stats = DoSPDY3CoDec(iterations, requests);
- pair<size_t, double> spdy4_stats = DoSPDY4CoDec(iterations, requests);
- PrintSummary("spdy3", spdy3_stats, iterations, request_header_bytes, header_count);
- PrintSummary("spdy4", spdy4_stats, iterations, request_header_bytes, header_count);
+#ifdef SPDY3
+ Stats spdy3_stats = DoSPDY3CoDec(time_to_iterate, requests);
+ PrintSummary("spdy3", spdy3_stats,
+ request_header_bytes, header_count);
+#endif
+ Stats spdy4_stats = DoSPDY4CoDec(time_to_iterate, requests);
+ PrintSummary("spdy4", spdy4_stats,
+ request_header_bytes, header_count);
}
Please sign in to comment.
Something went wrong with that request. Please try again.