# 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 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 + 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 + 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() + millis = int((stop_time - start_time) * 1000000) + 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() + \ No newline at end of file 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 @@ +#!/usr/bin/python +# +# Copyright 2007, 2008 VIFF Development Team. +# +# 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 +import time +import random +import timeit +from benchmark import Benchmark, parse_args + +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() + + # TODO: I'm not sure at all whether this is the right way of timing + # local multiplication. + 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} + + +# TODO: This is always needed. Make this more intuitive. +if __name__ == "__main__": + LocalMult(parse_args(sys.argv)).run_on_slave() + \ No newline at end of file diff -r ed614874c220 -r dd640eac89c5 apps/benchmark/examples/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/apps/benchmark/examples/__init__.py Fri Nov 07 00:48:39 2008 +0100 @@ -0,0 +1,17 @@ +# Copyright 2007, 2008 VIFF Development Team. +# +# 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/>. + _______________________________________________ viff-patches mailing list [email protected] http://lists.viff.dk/listinfo.cgi/viff-patches-viff.dk
