Commit aec5fda5 authored by Sergio Pérez's avatar Sergio Pérez
Browse files

Bencher benchmarks included:

* .erl -> original program
* .criterion -> slicing criterion (line var)
* .goldStandard -> minimal slice
* .sliced -> slice computed by the slicer
parent 91e8eaea
Loading
Loading
Loading
Loading
+55 −0
Original line number Diff line number Diff line
%-----------------------------------------------------------------------------------------
%-----------------------------------------------------------------------------------------
%-- bench10.erl
%--
%-- AUTHORS:     Tamarit
%-- DATE:        2016           
%-- PUBLISHED:   https://github.com/tamarit/hackerrank/tree/master/common-divisors (2016)
%--
%-- COPYLEFT:    This Erlang version is distributed in "Bencher: The Program Slicing 
%--              Benchmark Suite for Erlang" (Universitat Politècnica de València). 
%--              It is free of use and publicly available in the URL: 
%--              http://www.dsic.upv.es/~jsilva/slicing/bencher/
%--
%-- DESCRIPTION
%-- The program receives a list with pairs of integers and compute the number of common 
%-- divisors of each pair. The program returns a list with the number of common divisors
%-- in the same order as the input pairs.
%--
%-- SLICING CRITERION: (34,DB)
%-- SLICE: Available at: 
%--   http://www.dsic.upv.es/~jsilva/slicing/bencher/slices/b10_s34DB.erl
%-----------------------------------------------------------------------------------------
%-----------------------------------------------------------------------------------------
-module(bench10).
-export([main/1]).
main(L) ->
  Res = calculate(L).

calculate(List) ->
    calculate(List, []).

calculate([{A,B}|T], Acc) ->
    DA = divs(A),
    DB = divs(B),       % Slice here
    calculate(T, 
        [sets:size(
            sets:intersection(
                sets:from_list(DA), 
                sets:from_list(DB)))
        | Acc]);
calculate([], Acc) ->
    lists:reverse(Acc).

divs(0) -> [];
divs(1) -> [1];
divs(N) -> [1, N] ++ divisors(2,N,math:sqrt(N)).
 
divisors(K,_N,Q) when K > Q -> [];
divisors(K,N,Q) when N rem K =/= 0 -> 
    divisors(K+1,N,Q);
divisors(K,N,Q) when K * K  == N -> 
    [K] ++ divisors(K+1,N,Q);
divisors(K,N,Q) ->
    [K, N div K] ++ divisors(K+1,N,Q).
    
 No newline at end of file
+1 −0
Original line number Diff line number Diff line
34 DB
 No newline at end of file
+53 −0
Original line number Diff line number Diff line
%-----------------------------------------------------------------------------------------
%-----------------------------------------------------------------------------------------
%-- b10_s34DB.erl
%--
%-- AUTHORS:     Tamarit
%-- DATE:        2016           
%-- PUBLISHED:   This is the (only) minimal slice of the program solving the common
%--              divisors problem implemented in the file solution.erl available at: 
%--              https://github.com/tamarit/hackerrank/tree/master/common-divisors
%--
%-- COPYLEFT:    This Erlang version is distributed in "Bencher: The Program Slicing 
%--              Benchmark Suite for Erlang" (Universitat Politècnica de València). 
%--              It is free of use and publicly available in the URL: 
%--              http://www.dsic.upv.es/~jsilva/slicing/bencher/
%--
%-- DESCRIPTION
%-- The program receives a list with pairs of integers and compute the number of common 
%-- divisors of each pair. The program returns a list with the number of common divisors
%-- in the same order as the input pairs.
%--
%-- ORIGINAL PROGRAM: Available at: 
%--    http://www.dsic.upv.es/~jsilva/slicing/bencher/programs/bench10.erl
%-- SLICING CRITERION: (34,DB)/(Node 41)
%-----------------------------------------------------------------------------------------
%-----------------------------------------------------------------------------------------
-module(b10_s34DB).
-export([main/1]).

main(L) ->
    _ = calculate(L).

calculate(List) ->
    calculate(List, undef).

calculate([{_,B}|T], _) ->
    DB = divs(B),
    calculate(T, undef).

divs(0) ->
    [];
divs(1) ->
    [1];
divs(N) ->
    [1,N] ++ divisors(2, N, math:sqrt(N)).

divisors(K, _, Q) when K > Q ->
    [];
divisors(K, N, Q) when N rem K =/= 0 ->
    divisors(K + 1, N, Q);
divisors(K, N, Q) when K * K == N ->
    [K] ++ divisors(undef, undef, Q);
divisors(K, N, Q) ->
    [K,N div K] ++ divisors(K + 1, N, Q).
+32 −0
Original line number Diff line number Diff line
-module(bench10).

-export([main/1]).

main(L) ->
    calculate(L).

calculate(List) ->
    calculate(List, sliced).

calculate([{_, B} | T], _) ->
    DB = divs(B),
    calculate(T, sliced).

divs(0) ->
    [];
divs(1) ->
    [1];
divs(N) ->
    [1, N] ++ divisors(2, N, math:sqrt(N)).

divisors(K, _, Q) when K > Q ->
    [];
divisors(K, N, Q) when N rem K =/= 0 ->
    divisors(K + 1, N, Q);
divisors(K, N, Q) when K * K == N ->
    [K] ++ divisors(K + 1, N, Q);
divisors(K, N, Q) ->
    [K, N div K] ++ divisors(K + 1, N, Q).


+38 −0
Original line number Diff line number Diff line
%-----------------------------------------------------------------------------------------
%-----------------------------------------------------------------------------------------
%-- bench11.erl
%--
%-- AUTHORS: 	 Anonymous
%-- DATE:        2016           
%-- PUBLISHED:   Software specially developed to test non-called funtions.
%--
%-- COPYLEFT:    This Erlang version is distributed in "Bencher: The Program Slicing 
%--              Benchmark Suite for Erlang" (Universitat Politècnica de València). 
%--              It is free of use and publicly available in the URL: 
%--              http://www.dsic.upv.es/~jsilva/slicing/bencher/
%--
%-- DESCRIPTION
%-- This benchmark consists in a function that receives two lists as inputs and calls
%-- another one named fl with a conditional structure. There is also another function 
%-- gl that is not called by lists or fl.
%--
%-- SLICING CRITERION: (28,C)
%-- SLICE: Available at: 
%--   http://www.dsic.upv.es/~jsilva/slicing/bencher/slices/b11_s28C.erl
%-----------------------------------------------------------------------------------------
%-----------------------------------------------------------------------------------------
-module(bench11).
-export([lists/2]).

lists(A,B) -> 
	C=fl(A,B).		% Slice here
fl([H1|T1],[H2|T2]) -> 
	if	
		H1 >= 3 -> 
			H2;
		true -> 
			[H|_]=T2,
			H1-H  
	end.
gl([H|T]) -> 
	1.
 No newline at end of file
Loading