Monday, August 10, 2009

Protobuf JSON Serializer is great, but a bit slow

Run a small benchmark with the fresh new protobuf-java-format. The ProtobufJsonSerializer code is nice and trivial, greatly increasing the portability of protobuf and its capabilities to communicate with services that can't use the protobuf native parsing libraries.
Alas, it also comes with some price. Unfortunately, this new (still early) version of the library is very slow compared to other serialization libraries. See the full benchmarking wiki page for more info.

               Obj create, Serialization, Deserializtn,  Total Time, Size
protobuf , 421.14250, 3738.75000, 2471.25000, 6631.14250, 217
json (jackson), 235.45000, 3196.50000, 4934.25000, 8366.20000, 304
JsonMarshaller, 237.79000, 18107.00000, 24715.75000, 43060.54000, 298
protobuf-json , 431.94000, 19933.25000, 102577.75000,122942.94000, 389

EasyMock IArgumentMatcher with Scala Howto

Its pretty trivial if you're a Scala savvy, but for the learners it might be a bit tricky. First thing, you should probably first get familiar with the java way of using IArgumentMatcher. To use it you should have a static method that calls EasyMock.reportMatcher with your implementation of IArgumentMatcher. To archive that you must create the method in an object. Its a workaround for not having static methods in Scala. Then implement the matcher, pattern matching is lots of help here, and remember that in Scala AnyRef is equivalent to Java's Object.

object TestMyClazz {
* for EZMock argument matcher
def eqMyClazz(obj: MyClazz) : MyClazz = {
EasyMock.reportMatcher(new MyClazzMatcher(obj))

class MyClazzMatcher(obj: MyClazz) extends IArgumentMatcher {
def matches(actual: AnyRef): Boolean = actual match {
case actual: MyClazz => //check things...
case null => //is null ok?
case _ => false
def appendTo(buffer: StringBuffer) : Unit = buffer append "some text..."
Done, now you just need to call eqMyClazz() with your expected value.

Speaking at the QCon San Francisco '09 "Absorbing Scala"

Funny thing happened to me,
I checked out the new Google search engine on their sandbox url.
On of the things I searched for is my own name (very modest of me, I know...). I was a bit surprised to see I'm going to talk at QCon San Francisco 2009 about "Absorbing Scala". I remember discussing it a long while ago but it kinda trailed off and I forgot about it. They did got my current title wrong, not that it matters too much.

Anyway, its a yet another practical use of google search :-)

Hope there'll be more Scala nuts in the crowd to quiet down the other Language Zealot (by the way, I do love the groovy).

See you there!

Scala & EasyMock take II

Now that I'm using Scala's Manifest more, here is how my testing with EasyMock code looks like. Instead of

val mocked1 = EasyMock.createMock(classOf[MyClazz])
val mocked2 = EasyMock.createMock(classOf[MyOtherClazz])
val mocked1 = mock[MyClazz]
val mocked2 = mock[MyOtherClazz]
def mock[A](implicit m: Manifest[A]) = EasyMock.createMock(m.erasure).asInstanceOf[A]
Running the test using
run(mocked1, mocked2){
//code using mocks here
def run(mocks : AnyRef*)(block : => Unit){
replay(mocks : _*)
verify(mocks : _*)
reset(mocks : _*)

Creative Commons License This work by Eishay Smith is licensed under a Creative Commons Attribution 3.0 Unported License.