time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

runner.jl (1559B)


      1 #!/usr/bin/env julia
      2 #
      3 # @license Apache-2.0
      4 #
      5 # Copyright (c) 2018 The Stdlib Authors.
      6 #
      7 # Licensed under the Apache License, Version 2.0 (the "License");
      8 # you may not use this file except in compliance with the License.
      9 # You may obtain a copy of the License at
     10 #
     11 #    http://www.apache.org/licenses/LICENSE-2.0
     12 #
     13 # Unless required by applicable law or agreed to in writing, software
     14 # distributed under the License is distributed on an "AS IS" BASIS,
     15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16 # See the License for the specific language governing permissions and
     17 # limitations under the License.
     18 
     19 import JSON
     20 
     21 """
     22     gen( domain, name )
     23 
     24 Generate fixture data and write to file.
     25 
     26 # Arguments
     27 
     28 * `domain`: domain
     29 * `name::AbstractString`: output filename
     30 
     31 # Examples
     32 
     33 ``` julia
     34 julia> x = range( -0.999, stop = 0.999, length = 2001 );
     35 julia> gen( x, \"data.json\" );
     36 ```
     37 """
     38 function gen( domain, name )
     39 	x = collect( domain );
     40 	y = atanh.( x );
     41 
     42 	# Store data to be written to file as a collection:
     43 	data = Dict([
     44 		("x", x),
     45 		("expected", y)
     46 	]);
     47 
     48 	# Based on the script directory, create an output filepath:
     49 	filepath = joinpath( dir, name );
     50 
     51 	# Write the data to the output filepath as JSON:
     52 	outfile = open( filepath, "w" );
     53 	write( outfile, JSON.json(data) );
     54 	close( outfile );
     55 end
     56 
     57 # Get the filename:
     58 file = @__FILE__;
     59 
     60 # Extract the directory in which this file resides:
     61 dir = dirname( file );
     62 
     63 # Generate fixture data for decimal values:
     64 x = range( -0.99, stop = 0.99, length = 2003 );
     65 gen( x, "data.json" );