1# Copyright (C) 2013, Parrot Foundation.
2
3=head1 NAME
4
5examples/benchmarks/sort_ffa.pir - Sort an FixedFloatArray of N floats
6
7=head1 SYNOPSIS
8
9    % time ./parrot examples/benchmarks/sort_ffa.pir 100000
10
11Or use the default number of iterations:
12
13    % time ./parrot examples/benchmarks/sort.pir
14
15=head1 DESCRIPTION
16
17Sorts an FixedFloatArray of N random integers using builtin sort
18function for FixedFloatArray. The argument N is specified from the
19command line.
20
21=cut
22
23.loadlib 'math_ops'
24
25.sub main :main
26  .param pmc argv
27  .local int N, i, j
28
29  N = argv[1]
30  if N < 1 goto USE_DEFAULT_SIZE
31  goto USE_DEFINED_SIZE
32
33USE_DEFAULT_SIZE:
34  N = 1000000
35
36USE_DEFINED_SIZE:
37  $P0 = new ['FixedFloatArray'], N
38  i = 0
39  j = 0
40
41LOOP:
42  j = rand 0, N
43  $P0[i] = j
44  inc i
45  if i < N goto LOOP
46
47  $P0.'sort'()
48
49  print "Sorted "
50  print N
51  print " floats\n"
52
53.end
54
55
56# Local Variables:
57#   mode: pir
58#   fill-column: 100
59# End:
60# vim: expandtab shiftwidth=4 ft=pir:
61
62