Thomas Pelle Jakobsen <[EMAIL PROTECTED]> writes:

Hi Thomas,

I figured that I might as well start looking at this -- it doesn't seem
that anybody else will jump in :-)

> # HG changeset patch
> # User Thomas Pelle Jakobsen <[EMAIL PROTECTED]>
> # Date 1226015319 -3600
> # Node ID dd640eac89c544273c9e1a7230af6b44c975bf01
> # Parent  ed614874c220220495746906180caf9a2d5f258d
> Added example benchmarks.
>
> diff -r ed614874c220 -r dd640eac89c5 
> apps/benchmark/examples/ComparisonToft05.py
> --- /dev/null Thu Jan 01 00:00:00 1970 +0000
> +++ b/apps/benchmark/examples/ComparisonToft05.py     Fri Nov 07 00:48:39 
> 2008 +0100
> @@ -0,0 +1,83 @@
> +#!/usr/bin/python
> +#
> +# Copyright 2007, 2008 VIFF Development Team.

This is new code -- the copyright header should mention the years in
which the software is released. Mentioning the years where the software
has been edited is normally a good approximation.

I guess you don't use Emacs, but let me just note anyway that I use

  (add-hook 'before-save-hook 'copyright-update)

in my ~/.emacs file to automatically update any such copyright notices
whenever I save a file. So in a month the copyright headers will start
being updated as we work on the different files.

> +# This file is part of VIFF, the Virtual Ideal Functionality Framework.
> +#
> +# VIFF is free software: you can redistribute it and/or modify it
> +# under the terms of the GNU Lesser General Public License (LGPL) as
> +# published by the Free Software Foundation, either version 3 of the
> +# License, or (at your option) any later version.
> +#
> +# VIFF is distributed in the hope that it will be useful, but WITHOUT
> +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
> +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
> +# Public License for more details.
> +#
> +# You should have received a copy of the GNU Lesser General Public
> +# License along with VIFF. If not, see <http://www.gnu.org/licenses/>.
> +
> +import sys, time

> +from viff_benchmark import VIFFBenchmark
> +from benchmark import parse_args



> +from viff.runtime import gather_shares
> +from viff.comparison import Toft05Runtime
> +from viff.field import GF
> +
> +class ComparisonToft05(VIFFBenchmark):
> +    """ This is an example how to use the benchmark application.
> +    
> +    In the get_runtime_class method we specify that this benchmark should
> +    use the Toft05Runtime. The protocol method does the actual
> +    benchmarking. The protocol method is invoked on each benchmark
> +    host given the appropriate runtime and a dictionary of attributes. 
> +    This dictionary contains some predefined attributes like player_id, 
> +    n (number of players), etc. as well as the custom attributes that was 

The three precedings lines end with an extra space.

> +    specified in the benchmark constructor when adding the benchmark to
> +    the suite, e.g. modulus in this case.
> +    
> +    The protocol method schedules the setup of some random secret sharings.
> +    Then when they are ready, a timer is started, a comparison is done,
> +    and when that comparison finishes, the timer is stopped.
> +    
> +    The protocol method must return a dictionary of the form
> +    
> +        { attribute_name_1: value_1, attribute_name_2: value_2, ...}
> +    
> +    in this case { 'execution_time': x }.
> +    
> +    It is thus possible for one benchmark to measure values for 

Another trailing space.

> +    multiple attributes. TODO: It is not clear now whether this
> +    is a desired feature.
> +    
> +    """
> +    
> +    def get_runtime_class(self):
> +        return Toft05Runtime
> +    
> +    def start_timer(self, _):
> +        global start_time
> +        start_time = time.time()
> +
> +    def stop_timer(self, _):
> +        # Execution time is reported as whole microseconds.
> +        # TODO: Don't know if this is the best way measure the time.
> +        stop_time = time.time()

The time module says that the clock function is the most accurate time
source:

  http://docs.python.org/library/time.html#time.clock

But when I used it last, it kept giving me strage numbers. Maybe it was
because the timespan I tried to measure was so long that it would
overflow an float?

So I guess time.time is okay to use.

> +        millis = int((stop_time - start_time) * 1000000)

Should that not be micros? And why not keep it as seconds and as a
floating point number?

> +        return {'execution_time': millis}
> +    
> +    def protocol(self, rt, attr):
> +        Zp = GF(int(attr['modulus']))
> +        a = rt.prss_share_random(Zp)
> +        b = rt.prss_share_random(Zp)
> +        c = gather_shares([a,b])
> +        c.addCallback(self.start_timer)
> +        d = (a <= b)
> +        d.addCallback(self.stop_timer)
> +        return d
> +        
> +
> +# TODO: This is always needed. Make this more intuitive.
> +if __name__ == "__main__":
> +    ComparisonToft05(parse_args(sys.argv)).run_on_slave()

I guess this means that each benchmark becomes its own executable file?
Maybe it would be better to make one single executable file and then let
this file run the benchmark?

It could import the given file with

  bench = __import__(file)
  execute_benchmark_module(benc)

or something like that.

> \ No newline at end of file

You'll probably want a newline here.

> diff -r ed614874c220 -r dd640eac89c5 apps/benchmark/examples/LocalMult.py
> --- /dev/null Thu Jan 01 00:00:00 1970 +0000
> +++ b/apps/benchmark/examples/LocalMult.py    Fri Nov 07 00:48:39 2008 +0100
> @@ -0,0 +1,53 @@

> +class LocalMult(Benchmark):
> +    """This benchmark measures the time it takes to do a local multiplication
> +    of two Zp elements.
> +    
> +    It serves as an example of how to use the benchmark application to
> +    benchmark something that does not involve execution of a VIFF protocol.
> +    """
> +    
> +    def setup(self, attr):
> +        random.seed()

I believe the random module seeds itself as necessary.

> +    # TODO: I'm not sure at all whether this is the right way of timing
> +    # local multiplication.

Hmm, well, ... Using timeit it cool, but having to define the benchmark
as a text string is not. Maybe we could see how timeit works and then do
something similar, but on real code?

> +    def benchmark(self, attr):
> +        a = random.randint(0, int(attr['modulus']))
> +        b = random.randint(0, int(attr['modulus']))
> +        pre = "from viff.field import GF\nZp=GF(%s)\na = Zp(%s)\nb = Zp(%s)" 
> %\
> +            (attr['modulus'], str(a), str(b))
> +        t = timeit.Timer(stmt="c = a * b", setup=pre)
> +        time = t.timeit()
> +        micro_seconds = int(time * 1000)
> +        return {'execution_time': micro_seconds}

-- 
Martin Geisler

Attachment: pgpuWU6gDvclT.pgp
Description: PGP signature

_______________________________________________
viff-patches mailing list
viff-patches@viff.dk
http://lists.viff.dk/listinfo.cgi/viff-patches-viff.dk

Reply via email to