0029399: Optimize reading of floating point values from text strings
[occt.git] / tests / perf / fclasses / strtod
1 puts "================================================================="
2 puts "Testing performance of Strtod() vs. standard strtod()"
3 puts "================================================================="
4 puts ""
5
6 pload QAcommands
7
8 # Check that performance of Strtod() and Atof() is at least twice better 
9 # than that of standard strtod() and atof()
10 proc CheckAtof {nbvalues nbdigits min max} {
11   set res [QATestAtof $nbvalues $nbdigits $min $max]
12 #  puts $res
13
14   if { ! [regexp {atof\s+([0-9.]+)} $res bidon cpu_atof] ||
15        ! [regexp {Atof\s+([0-9.]+)} $res bidon cpu_Atof] ||
16        ! [regexp {strtod\s+([0-9.]+)} $res bidon cpu_strtod] ||
17        ! [regexp {Strtod\s+([0-9.]+)} $res bidon cpu_Strtod] } {
18     puts "Error: cannot interpret results of test command!"
19   } else {
20     if { $cpu_atof < 2 * $cpu_Atof } {
21       puts "Error: Atof() is expected to be at least 2 times better than atof()!"
22     }
23     if { $cpu_strtod < 2 * $cpu_Strtod } {
24       puts "Error: Strtod() is expected to be at least 2 times better than strtod()!"
25     }
26   }
27 }
28
29 puts "1M random values, 10 significant digits, in range (-1e9, 1e9)"
30 CheckAtof 1000000 10 -1e9 1e9
31
32 puts "1M random values, 10 significant digits, in range (-1e305, 1e305)"
33 CheckAtof 1000000 10 -1e305 1e305
34
35 puts "1M random values, 16 significant digits, in range (-1e9, 1e9)"
36 CheckAtof 1000000 16 -1e9 1e9
37
38 puts "1M random values, 18 significant digits, in range (-1e305, 1e305)"
39 CheckAtof 1000000 16 -1e305 1e305
40
41 # Disarm FPE signals - otherwise they will be raised if signaling NAN appears
42 dsetsignal 0
43
44 puts "Special values + 1M values defined by random binary data, 10 digits"
45 CheckAtof 1000000 10 0 0
46
47 puts "Special values + 1M values defined by random binary data, 16 digits"
48 CheckAtof 1000000 16 0 0