monotone-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Monotone-devel] hex en/decode speed measurement: 40% reduction by using


From: Christof Petig
Subject: [Monotone-devel] hex en/decode speed measurement: 40% reduction by using the old specialized versions by graydon (2006) again
Date: Sun, 04 May 2008 13:29:01 +0200
User-agent: Thunderbird 2.0.0.12 (X11/20080227)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

mtn: Zertifikate | Schlüssel | Revisionen
mtn:      76.702 |        74 |     25.283
mtn: Bytes rein | Bytes raus | Zertifikate rein | Revisionen rein
mtn:      1,1 M |    361,4 k |          560/560 |         136/136
mtn: erfolgreicher Austausch mit localhost

monotone 0.40 (Basis-Revision: bfc2ecb16c1e9da1a15745f7537bd773266d7b28)
real    11m45.777s
user    11m23.151s
sys     0m1.444s

monotone 0.40 (Basis-Revision: 01113d80b5e63f04da293f024783ee6c926a37f6)
real    12m2.858s
user    11m19.914s
sys     0m2.612s

with this patch
real    7m25.268s
user    7m1.642s
sys     0m0.888s
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIHZ38ng+R+0ucfO0RAvHLAKC/Hmlm58qklsvAploE8hz7Cn3Y9wCfYz5/
PgbxAJIzJlbgbHNXvubyABA=
=j//P
-----END PGP SIGNATURE-----
#
# old_revision [15be8e6d3d9a788a082c6305084d3381e4c40ff7]
#
# patch "transforms.cc"
#  from [344c1f23d33145b51f0fc500014a75da95b3c115]
#    to [601bd492e66bd2a7601f5685030b298656148518]
#
============================================================
--- transforms.cc       344c1f23d33145b51f0fc500014a75da95b3c115
+++ transforms.cc       601bd492e66bd2a7601f5685030b298656148518
@@ -17,6 +17,7 @@
 #include "transforms.hh"
 #include "xdelta.hh"
 #include "char_classifiers.hh"
+#include "constants.hh"
 
 using std::string;
 using Botan::Pipe;
@@ -120,11 +121,105 @@ SPECIALIZE_XFORM(Base64_Decoder, Botan::
 
 SPECIALIZE_XFORM(Base64_Encoder,);
 SPECIALIZE_XFORM(Base64_Decoder, Botan::IGNORE_WS);
-SPECIALIZE_XFORM(Hex_Encoder, Hex_Encoder::Lowercase);
-SPECIALIZE_XFORM(Hex_Decoder, Botan::IGNORE_WS);
+//SPECIALIZE_XFORM(Hex_Encoder, Hex_Encoder::Lowercase);
+//SPECIALIZE_XFORM(Hex_Decoder, Botan::IGNORE_WS);
 SPECIALIZE_XFORM(Gzip_Compression,);
 SPECIALIZE_XFORM(Gzip_Decompression,);
 
+static inline char
+decode_hex_char(char c)
+{
+  if (c >= '0' && c <= '9')
+    return c - '0';
+  else
+  {
+          I(c >= 'a' && c <= 'f');
+          return c - 'a' + 10;
+  }
+}
+
+static inline void
+decode_hexenc_inner(string::const_iterator i,
+                    string::const_iterator end,
+                    char *out)
+{
+  for (; i != end; ++i)
+    {
+      char t = decode_hex_char(*i++);
+      t <<= 4;
+      t |= decode_hex_char(*i);
+      *out++ = t;
+    }
+}
+
+template<> string xform<Hex_Decoder>(string const & in)
+  {
+    string out;
+    try
+      {
+        if (LIKELY(in.size() == constants::idlen))
+          {
+            I(in.size() % 2 == 0);
+            char buf[constants::idlen / 2];
+            decode_hexenc_inner(in.begin(), in.end(), buf);
+            return string(buf, constants::idlen / 2);
+          }
+        else
+        {
+          static cached_botan_pipe pipe(new Pipe(new 
Hex_Decoder(Botan::IGNORE_WS)));
+          /* this might actually be a problem here */
+          I(pipe->message_count() < Pipe::LAST_MESSAGE);
+          pipe->process_msg(in);
+          out = pipe->read_all_as_string(Pipe::LAST_MESSAGE);
+        }
+      }
+    catch (Botan::Exception & e)
+      {
+        error_in_transform(e);
+      }
+    return out;
+  }
+
+static inline void
+encode_hexenc_inner(string::const_iterator i,
+                    string::const_iterator end,
+                    char *out)
+{
+  static char const *tab = "0123456789abcdef";
+  for (; i != end; ++i)
+    {
+      *out++ = tab[(*i >> 4) & 0xf];
+      *out++ = tab[*i & 0xf];
+    }
+}
+
+template<> string xform<Hex_Encoder>(string const & in)
+  {
+    string out;
+    try
+      {
+        if (LIKELY(in.size() == constants::idlen / 2))
+          {
+            char buf[constants::idlen];
+            encode_hexenc_inner(in.begin(), in.end(), buf);
+            return string(buf, constants::idlen);
+          }
+        else
+        {
+          static cached_botan_pipe pipe(new Pipe(new 
Hex_Encoder(Hex_Encoder::Lowercase)));
+          /* this might actually be a problem here */
+          I(pipe->message_count() < Pipe::LAST_MESSAGE);
+          pipe->process_msg(in);
+          out = pipe->read_all_as_string(Pipe::LAST_MESSAGE);
+        }
+      }
+    catch (Botan::Exception & e)
+      {
+        error_in_transform(e);
+      }
+    return out;
+  }
+
 template <typename T>
 void pack(T const & in, base64< gzip<T> > & out)
 {

reply via email to

[Prev in Thread] Current Thread [Next in Thread]