> *I am asking you to do some performance analysis. Specifically, would*
> *you** please profile a curve and a straight segment to compare?*

Sure, here is the average of 1 million iteration of computing shortest
distance from a point to both types of curves and line segments:
(using -O3 optimization, measured using chrono library)

A) Line Segment: ~0.32 microseconds
B) Conic Bezier: ~1.08 microseconds
C) Cubic Bezier: ~1.25 microseconds

[I have also attached the gprof output in case you are interested. Note
that the gprof output is without any compiler optimization]

> *We need to know if it is worth simply splitting the curve into a large*
> *number of straight segments. How many straight segments we can afford*
> *and still beat the exact solution.*

In my opinion it's not worth splitting the curves into line segments.
But if there is a way to not check each and every line segment, then
it might be worth giving it a try.

> *Sure, but please use your dedicated branch.*

Yes, I will do that.

Anuj
Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls  us/call  us/call  name    
 57.03      1.38     1.38  8378453     0.16     0.16  ft_trig_pseudo_polarize
 16.12      1.77     0.39  1000000     0.39     2.38  get_min_distance [for 
cubic curves]
 13.64      2.10     0.33 153570100     0.00     0.00  FT_MulFix_x86_64
  4.55      2.21     0.11  1000000     0.11     0.11  FT_Vector_NormLen
  2.89      2.28     0.07  8378453     0.01     0.01  ft_trig_prenorm
  1.86      2.33     0.05  7378505     0.01     0.01  FT_DivFix
  1.65      2.37     0.04  8378505     0.00     0.18  FT_Vector_Length
  1.24      2.40     0.03                             main
  0.41      2.41     0.01  8378453     0.00     0.00  ft_trig_downscale
  0.41      2.42     0.01                             FT_Vector_Rotate
  0.21      2.42     0.01                             FT_MulFix

 %         the percentage of the total running time of the
time       program used by this function.

cumulative a running sum of the number of seconds accounted
 seconds   for by this function and those listed above it.

 self      the number of seconds accounted for by this
seconds    function alone.  This is the major sort for this
           listing.

calls      the number of times this function was invoked, if
           this function is profiled, else blank.

 self      the average number of milliseconds spent in this
ms/call    function per call, if this function is profiled,
           else blank.

 total     the average number of milliseconds spent in this
ms/call    function and its descendents per call, if this
           function is profiled, else blank.

name       the name of the function.  This is the minor sort
           for this listing. The index shows the location of
           the function in the gprof listing. If the index is
           in parenthesis it shows where it would appear in
           the gprof listing if it were to be printed.

Copyright (C) 2012-2020 Free Software Foundation, Inc.

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.

                     Call graph (explanation follows)


granularity: each sample hit covers 2 byte(s) for 0.41% of 2.42 seconds

index % time    self  children    called     name
                                                 <spontaneous>
[1]     99.4    0.03    2.38                 main [1]
                0.39    1.99 1000000/1000000     get_min_distance [2]
-----------------------------------------------
                0.39    1.99 1000000/1000000     main [1]
[2]     98.1    0.39    1.99 1000000         get_min_distance [2]
                0.04    1.46 8378505/8378505     FT_Vector_Length [3]
                0.33    0.00 153570100/153570100     FT_MulFix_x86_64 [5]
                0.11    0.00 1000000/1000000     FT_Vector_NormLen [6]
                0.05    0.00 7378505/7378505     FT_DivFix [8]
-----------------------------------------------
                0.04    1.46 8378505/8378505     get_min_distance [2]
[3]     62.0    0.04    1.46 8378505         FT_Vector_Length [3]
                1.38    0.00 8378453/8378453     ft_trig_pseudo_polarize [4]
                0.07    0.00 8378453/8378453     ft_trig_prenorm [7]
                0.01    0.00 8378453/8378453     ft_trig_downscale [9]
-----------------------------------------------
                1.38    0.00 8378453/8378453     FT_Vector_Length [3]
[4]     57.0    1.38    0.00 8378453         ft_trig_pseudo_polarize [4]
-----------------------------------------------
                0.33    0.00 153570100/153570100     get_min_distance [2]
[5]     13.6    0.33    0.00 153570100         FT_MulFix_x86_64 [5]
-----------------------------------------------
                0.11    0.00 1000000/1000000     get_min_distance [2]
[6]      4.5    0.11    0.00 1000000         FT_Vector_NormLen [6]
-----------------------------------------------
                0.07    0.00 8378453/8378453     FT_Vector_Length [3]
[7]      2.9    0.07    0.00 8378453         ft_trig_prenorm [7]
-----------------------------------------------
                0.05    0.00 7378505/7378505     get_min_distance [2]
[8]      1.9    0.05    0.00 7378505         FT_DivFix [8]
-----------------------------------------------
                0.01    0.00 8378453/8378453     FT_Vector_Length [3]
[9]      0.4    0.01    0.00 8378453         ft_trig_downscale [9]
-----------------------------------------------
                                                 <spontaneous>
[10]     0.4    0.01    0.00                 FT_Vector_Rotate [10]
-----------------------------------------------
                                                 <spontaneous>
[11]     0.2    0.01    0.00                 FT_MulFix [11]
-----------------------------------------------

 This table describes the call tree of the program, and was sorted by
 the total amount of time spent in each function and its children.

 Each entry in this table consists of several lines.  The line with the
 index number at the left hand margin lists the current function.
 The lines above it list the functions that called this function,
 and the lines below it list the functions this one called.
 This line lists:
     index      A unique number given to each element of the table.
                Index numbers are sorted numerically.
                The index number is printed next to every function name so
                it is easier to look up where the function is in the table.

     % time     This is the percentage of the `total' time that was spent
                in this function and its children.  Note that due to
                different viewpoints, functions excluded by options, etc,
                these numbers will NOT add up to 100%.

     self       This is the total amount of time spent in this function.

     children   This is the total amount of time propagated into this
                function by its children.

     called     This is the number of times the function was called.
                If the function called itself recursively, the number
                only includes non-recursive calls, and is followed by
                a `+' and the number of recursive calls.

     name       The name of the current function.  The index number is
                printed after it.  If the function is a member of a
                cycle, the cycle number is printed between the
                function's name and the index number.


 For the function's parents, the fields have the following meanings:

     self       This is the amount of time that was propagated directly
                from the function into this parent.

     children   This is the amount of time that was propagated from
                the function's children into this parent.

     called     This is the number of times this parent called the
                function `/' the total number of times the function
                was called.  Recursive calls to the function are not
                included in the number after the `/'.

     name       This is the name of the parent.  The parent's index
                number is printed after it.  If the parent is a
                member of a cycle, the cycle number is printed between
                the name and the index number.

 If the parents of the function cannot be determined, the word
 `<spontaneous>' is printed in the `name' field, and all the other
 fields are blank.

 For the function's children, the fields have the following meanings:

     self       This is the amount of time that was propagated directly
                from the child into the function.

     children   This is the amount of time that was propagated from the
                child's children to the function.

     called     This is the number of times the function called
                this child `/' the total number of times the child
                was called.  Recursive calls by the child are not
                listed in the number after the `/'.

     name       This is the name of the child.  The child's index
                number is printed after it.  If the child is a
                member of a cycle, the cycle number is printed
                between the name and the index number.

 If there are any cycles (circles) in the call graph, there is an
 entry for the cycle-as-a-whole.  This entry shows who called the
 cycle (as parents) and the members of the cycle (as children.)
 The `+' recursive calls entry shows the number of function calls that
 were internal to the cycle, and the calls entry for each member shows,
 for that member, how many times it was called from other members of
 the cycle.

Copyright (C) 2012-2020 Free Software Foundation, Inc.

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.

Index by function name

   [8] FT_DivFix               [6] FT_Vector_NormLen (ftcalc.c) [4] 
ft_trig_pseudo_polarize (fttrigon.c)
  [11] FT_MulFix              [10] FT_Vector_Rotate        [2] get_min_distance
   [5] FT_MulFix_x86_64 (ftcalc.h) [9] ft_trig_downscale (fttrigon.c) [1] main
   [3] FT_Vector_Length        [7] ft_trig_prenorm (fttrigon.c)
Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls  ns/call  ns/call  name    
 57.79      0.26     0.26  1999998   130.02   130.02  ft_trig_pseudo_polarize
 31.12      0.40     0.14  2000000    70.01    70.01  FT_Vector_NormLen
  6.67      0.43     0.03  1000000    30.00    30.00  FT_DivFix
  2.22      0.44     0.01  4000000     2.50     2.50  FT_MulFix_x86_64
  2.22      0.45     0.01  1999998     5.00     5.00  ft_trig_prenorm
  0.00      0.45     0.00  2000000     0.00   135.02  FT_Vector_Length
  0.00      0.45     0.00  1999998     0.00     0.00  ft_trig_downscale
  0.00      0.45     0.00  1000000     0.00   450.06  get_min_distance [for 
line segments]

 %         the percentage of the total running time of the
time       program used by this function.

cumulative a running sum of the number of seconds accounted
 seconds   for by this function and those listed above it.

 self      the number of seconds accounted for by this
seconds    function alone.  This is the major sort for this
           listing.

calls      the number of times this function was invoked, if
           this function is profiled, else blank.

 self      the average number of milliseconds spent in this
ms/call    function per call, if this function is profiled,
           else blank.

 total     the average number of milliseconds spent in this
ms/call    function and its descendents per call, if this
           function is profiled, else blank.

name       the name of the function.  This is the minor sort
           for this listing. The index shows the location of
           the function in the gprof listing. If the index is
           in parenthesis it shows where it would appear in
           the gprof listing if it were to be printed.

Copyright (C) 2012-2020 Free Software Foundation, Inc.

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.

                     Call graph (explanation follows)


granularity: each sample hit covers 2 byte(s) for 2.22% of 0.45 seconds

index % time    self  children    called     name
                0.00    0.45 1000000/1000000     main [2]
[1]    100.0    0.00    0.45 1000000         get_min_distance [1]
                0.00    0.27 2000000/2000000     FT_Vector_Length [3]
                0.14    0.00 2000000/2000000     FT_Vector_NormLen [5]
                0.03    0.00 1000000/1000000     FT_DivFix [6]
                0.01    0.00 4000000/4000000     FT_MulFix_x86_64 [7]
-----------------------------------------------
                                                 <spontaneous>
[2]    100.0    0.00    0.45                 main [2]
                0.00    0.45 1000000/1000000     get_min_distance [1]
-----------------------------------------------
                0.00    0.27 2000000/2000000     get_min_distance [1]
[3]     60.0    0.00    0.27 2000000         FT_Vector_Length [3]
                0.26    0.00 1999998/1999998     ft_trig_pseudo_polarize [4]
                0.01    0.00 1999998/1999998     ft_trig_prenorm [8]
                0.00    0.00 1999998/1999998     ft_trig_downscale [9]
-----------------------------------------------
                0.26    0.00 1999998/1999998     FT_Vector_Length [3]
[4]     57.8    0.26    0.00 1999998         ft_trig_pseudo_polarize [4]
-----------------------------------------------
                0.14    0.00 2000000/2000000     get_min_distance [1]
[5]     31.1    0.14    0.00 2000000         FT_Vector_NormLen [5]
-----------------------------------------------
                0.03    0.00 1000000/1000000     get_min_distance [1]
[6]      6.7    0.03    0.00 1000000         FT_DivFix [6]
-----------------------------------------------
                0.01    0.00 4000000/4000000     get_min_distance [1]
[7]      2.2    0.01    0.00 4000000         FT_MulFix_x86_64 [7]
-----------------------------------------------
                0.01    0.00 1999998/1999998     FT_Vector_Length [3]
[8]      2.2    0.01    0.00 1999998         ft_trig_prenorm [8]
-----------------------------------------------
                0.00    0.00 1999998/1999998     FT_Vector_Length [3]
[9]      0.0    0.00    0.00 1999998         ft_trig_downscale [9]
-----------------------------------------------

 This table describes the call tree of the program, and was sorted by
 the total amount of time spent in each function and its children.

 Each entry in this table consists of several lines.  The line with the
 index number at the left hand margin lists the current function.
 The lines above it list the functions that called this function,
 and the lines below it list the functions this one called.
 This line lists:
     index      A unique number given to each element of the table.
                Index numbers are sorted numerically.
                The index number is printed next to every function name so
                it is easier to look up where the function is in the table.

     % time     This is the percentage of the `total' time that was spent
                in this function and its children.  Note that due to
                different viewpoints, functions excluded by options, etc,
                these numbers will NOT add up to 100%.

     self       This is the total amount of time spent in this function.

     children   This is the total amount of time propagated into this
                function by its children.

     called     This is the number of times the function was called.
                If the function called itself recursively, the number
                only includes non-recursive calls, and is followed by
                a `+' and the number of recursive calls.

     name       The name of the current function.  The index number is
                printed after it.  If the function is a member of a
                cycle, the cycle number is printed between the
                function's name and the index number.


 For the function's parents, the fields have the following meanings:

     self       This is the amount of time that was propagated directly
                from the function into this parent.

     children   This is the amount of time that was propagated from
                the function's children into this parent.

     called     This is the number of times this parent called the
                function `/' the total number of times the function
                was called.  Recursive calls to the function are not
                included in the number after the `/'.

     name       This is the name of the parent.  The parent's index
                number is printed after it.  If the parent is a
                member of a cycle, the cycle number is printed between
                the name and the index number.

 If the parents of the function cannot be determined, the word
 `<spontaneous>' is printed in the `name' field, and all the other
 fields are blank.

 For the function's children, the fields have the following meanings:

     self       This is the amount of time that was propagated directly
                from the child into the function.

     children   This is the amount of time that was propagated from the
                child's children to the function.

     called     This is the number of times the function called
                this child `/' the total number of times the child
                was called.  Recursive calls by the child are not
                listed in the number after the `/'.

     name       This is the name of the child.  The child's index
                number is printed after it.  If the child is a
                member of a cycle, the cycle number is printed
                between the name and the index number.

 If there are any cycles (circles) in the call graph, there is an
 entry for the cycle-as-a-whole.  This entry shows who called the
 cycle (as parents) and the members of the cycle (as children.)
 The `+' recursive calls entry shows the number of function calls that
 were internal to the cycle, and the calls entry for each member shows,
 for that member, how many times it was called from other members of
 the cycle.

Copyright (C) 2012-2020 Free Software Foundation, Inc.

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.

Index by function name

   [6] FT_DivFix               [5] FT_Vector_NormLen (ftcalc.c) [4] 
ft_trig_pseudo_polarize (fttrigon.c)
   [7] FT_MulFix_x86_64 (ftcalc.h) [9] ft_trig_downscale (fttrigon.c) [1] 
get_min_distance
   [3] FT_Vector_Length        [8] ft_trig_prenorm (fttrigon.c)
Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls  us/call  us/call  name    
 30.14      0.44     0.44  3818733     0.12     0.12  ft_trig_pseudo_polarize
 28.77      0.86     0.42  4999885     0.08     0.08  square_root
  9.59      1.00     0.14 51985248     0.00     0.00  FT_MulFix_x86_64
  9.59      1.14     0.14  2000000     0.07     0.07  FT_Vector_NormLen
  6.17      1.23     0.09  1000000     0.09     1.44  get_min_distance [for 
conic curves]
  4.11      1.29     0.06  1999946     0.03     0.25  cube_root
  3.43      1.34     0.05  3999998     0.01     0.13  FT_Vector_Length
  2.74      1.38     0.04 11995084     0.00     0.00  FT_DivFix
  2.74      1.42     0.04  1000000     0.04     0.65  solve_cubic_equation
  1.37      1.44     0.02  3818733     0.01     0.01  ft_trig_prenorm
  1.37      1.46     0.02                             main
  0.00      1.46     0.00  3818733     0.00     0.00  ft_trig_downscale
  0.00      1.46     0.00       27     0.00     0.08  solve_quadratic_equation

 %         the percentage of the total running time of the
time       program used by this function.

cumulative a running sum of the number of seconds accounted
 seconds   for by this function and those listed above it.

 self      the number of seconds accounted for by this
seconds    function alone.  This is the major sort for this
           listing.

calls      the number of times this function was invoked, if
           this function is profiled, else blank.

 self      the average number of milliseconds spent in this
ms/call    function per call, if this function is profiled,
           else blank.

 total     the average number of milliseconds spent in this
ms/call    function and its descendents per call, if this
           function is profiled, else blank.

name       the name of the function.  This is the minor sort
           for this listing. The index shows the location of
           the function in the gprof listing. If the index is
           in parenthesis it shows where it would appear in
           the gprof listing if it were to be printed.

Copyright (C) 2012-2020 Free Software Foundation, Inc.

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.

                     Call graph (explanation follows)


granularity: each sample hit covers 2 byte(s) for 0.68% of 1.46 seconds

index % time    self  children    called     name
                                                 <spontaneous>
[1]    100.0    0.02    1.44                 main [1]
                0.09    1.35 1000000/1000000     get_min_distance [2]
-----------------------------------------------
                0.09    1.35 1000000/1000000     main [1]
[2]     98.6    0.09    1.35 1000000         get_min_distance [2]
                0.04    0.61 1000000/1000000     solve_cubic_equation [3]
                0.05    0.46 3999998/3999998     FT_Vector_Length [4]
                0.14    0.00 2000000/2000000     FT_Vector_NormLen [9]
                0.05    0.00 19000013/51985248     FT_MulFix_x86_64 [8]
-----------------------------------------------
                0.04    0.61 1000000/1000000     get_min_distance [2]
[3]     44.4    0.04    0.61 1000000         solve_cubic_equation [3]
                0.06    0.44 1999946/1999946     cube_root [5]
                0.08    0.00  999972/4999885     square_root [7]
                0.02    0.00 5999838/51985248     FT_MulFix_x86_64 [8]
                0.01    0.00 2999919/11995084     FT_DivFix [10]
                0.00    0.00      27/27          solve_quadratic_equation [12]
-----------------------------------------------
                0.05    0.46 3999998/3999998     get_min_distance [2]
[4]     34.9    0.05    0.46 3999998         FT_Vector_Length [4]
                0.44    0.00 3818733/3818733     ft_trig_pseudo_polarize [6]
                0.02    0.00 3818733/3818733     ft_trig_prenorm [11]
                0.00    0.00 3818733/3818733     ft_trig_downscale [13]
-----------------------------------------------
                0.06    0.44 1999946/1999946     solve_cubic_equation [3]
[5]     34.2    0.06    0.44 1999946         cube_root [5]
                0.34    0.00 3999890/4999885     square_root [7]
                0.07    0.00 26985351/51985248     FT_MulFix_x86_64 [8]
                0.03    0.00 8995117/11995084     FT_DivFix [10]
-----------------------------------------------
                0.44    0.00 3818733/3818733     FT_Vector_Length [4]
[6]     30.1    0.44    0.00 3818733         ft_trig_pseudo_polarize [6]
-----------------------------------------------
                0.00    0.00      23/4999885     solve_quadratic_equation [12]
                0.08    0.00  999972/4999885     solve_cubic_equation [3]
                0.34    0.00 3999890/4999885     cube_root [5]
[7]     28.8    0.42    0.00 4999885         square_root [7]
-----------------------------------------------
                0.00    0.00      46/51985248     solve_quadratic_equation [12]
                0.02    0.00 5999838/51985248     solve_cubic_equation [3]
                0.05    0.00 19000013/51985248     get_min_distance [2]
                0.07    0.00 26985351/51985248     cube_root [5]
[8]      9.6    0.14    0.00 51985248         FT_MulFix_x86_64 [8]
-----------------------------------------------
                0.14    0.00 2000000/2000000     get_min_distance [2]
[9]      9.6    0.14    0.00 2000000         FT_Vector_NormLen [9]
-----------------------------------------------
                0.00    0.00      48/11995084     solve_quadratic_equation [12]
                0.01    0.00 2999919/11995084     solve_cubic_equation [3]
                0.03    0.00 8995117/11995084     cube_root [5]
[10]     2.7    0.04    0.00 11995084         FT_DivFix [10]
-----------------------------------------------
                0.02    0.00 3818733/3818733     FT_Vector_Length [4]
[11]     1.4    0.02    0.00 3818733         ft_trig_prenorm [11]
-----------------------------------------------
                0.00    0.00      27/27          solve_cubic_equation [3]
[12]     0.0    0.00    0.00      27         solve_quadratic_equation [12]
                0.00    0.00      23/4999885     square_root [7]
                0.00    0.00      48/11995084     FT_DivFix [10]
                0.00    0.00      46/51985248     FT_MulFix_x86_64 [8]
-----------------------------------------------
                0.00    0.00 3818733/3818733     FT_Vector_Length [4]
[13]     0.0    0.00    0.00 3818733         ft_trig_downscale [13]
-----------------------------------------------

 This table describes the call tree of the program, and was sorted by
 the total amount of time spent in each function and its children.

 Each entry in this table consists of several lines.  The line with the
 index number at the left hand margin lists the current function.
 The lines above it list the functions that called this function,
 and the lines below it list the functions this one called.
 This line lists:
     index      A unique number given to each element of the table.
                Index numbers are sorted numerically.
                The index number is printed next to every function name so
                it is easier to look up where the function is in the table.

     % time     This is the percentage of the `total' time that was spent
                in this function and its children.  Note that due to
                different viewpoints, functions excluded by options, etc,
                these numbers will NOT add up to 100%.

     self       This is the total amount of time spent in this function.

     children   This is the total amount of time propagated into this
                function by its children.

     called     This is the number of times the function was called.
                If the function called itself recursively, the number
                only includes non-recursive calls, and is followed by
                a `+' and the number of recursive calls.

     name       The name of the current function.  The index number is
                printed after it.  If the function is a member of a
                cycle, the cycle number is printed between the
                function's name and the index number.


 For the function's parents, the fields have the following meanings:

     self       This is the amount of time that was propagated directly
                from the function into this parent.

     children   This is the amount of time that was propagated from
                the function's children into this parent.

     called     This is the number of times this parent called the
                function `/' the total number of times the function
                was called.  Recursive calls to the function are not
                included in the number after the `/'.

     name       This is the name of the parent.  The parent's index
                number is printed after it.  If the parent is a
                member of a cycle, the cycle number is printed between
                the name and the index number.

 If the parents of the function cannot be determined, the word
 `<spontaneous>' is printed in the `name' field, and all the other
 fields are blank.

 For the function's children, the fields have the following meanings:

     self       This is the amount of time that was propagated directly
                from the child into the function.

     children   This is the amount of time that was propagated from the
                child's children to the function.

     called     This is the number of times the function called
                this child `/' the total number of times the child
                was called.  Recursive calls by the child are not
                listed in the number after the `/'.

     name       This is the name of the child.  The child's index
                number is printed after it.  If the child is a
                member of a cycle, the cycle number is printed
                between the name and the index number.

 If there are any cycles (circles) in the call graph, there is an
 entry for the cycle-as-a-whole.  This entry shows who called the
 cycle (as parents) and the members of the cycle (as children.)
 The `+' recursive calls entry shows the number of function calls that
 were internal to the cycle, and the calls entry for each member shows,
 for that member, how many times it was called from other members of
 the cycle.

Copyright (C) 2012-2020 Free Software Foundation, Inc.

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.

Index by function name

  [10] FT_DivFix              [13] ft_trig_downscale (fttrigon.c) [3] 
solve_cubic_equation
   [8] FT_MulFix_x86_64 (ftcalc.h) [11] ft_trig_prenorm (fttrigon.c) [12] 
solve_quadratic_equation
   [4] FT_Vector_Length        [6] ft_trig_pseudo_polarize (fttrigon.c) [7] 
square_root (ext.h)
   [9] FT_Vector_NormLen (ftcalc.c) [2] get_min_distance
   [5] cube_root (ext.h)       [1] main

Reply via email to