function legend_perf ()
  nplots = 8;
  npoints = 3;
  markers = {"*", "^", "*", "^", "*", "^", "v", ...
             "none", "^", "none", "none", "none", ...
             "none", "none", "none", "none"};
  
  wd = [2 2 2 2 2 2 2 4 2 4 4 4 4 4 1 1];
  leg = {};
  info = struct ("name", "", "time", 0.0, "toolkit", "");
  tk = "gnuplot";
  it = 0;

  for tk = {"qt", "gnuplot"}
    tk = tk{1}
    graphics_toolkit (tk);
    close all;
    figure (56789, "visible", "off");
    clf ();
    hold on;

    name = "Construct legend without markers at once";
    it ++;
    printf ("\n*** %s\n", name)
    info(it).name = name;
    info(it).toolkit = tk;info(it).time = 0.0;
    tic ()
    for ii = 1:nplots
      y = rand(1, npoints);
      plot (y);
      leg{ii} = ['foo ' num2str(ii)];
    end
    hl = legend (leg);
    info(it).time = toc (); toc ()
    clf ();
    hold on;

    name = "Construct legend at once";
    it ++;
    printf ("\n*** %s\n", name)
    info(it).name = name;
    info(it).toolkit = tk;info(it).time = 0.0;
    tic ()
    for ii = 1:nplots
      y = rand(1, npoints);
      plot (y, "marker", markers{ii}, "linewidth", wd(ii)/2);
      leg{ii} = ['foo ' num2str(ii)];
    end
    hl = legend (leg);
    info(it).time = toc (); toc ()
    clf ();
    hold on;

    name = "Construct legend item after item";
    it ++;
    printf ("\n*** %s\n", name)
    info(it).name = name;
    info(it).toolkit = tk;info(it).time = 0.0;
    tic ()
    for ii = 1:nplots
      y = rand(1, npoints);
      plot (y, sprintf (";foo %d;", ii), ...
            "marker", markers{ii}, "linewidth", wd(ii)/2);
    end
    hl = legend ();
    info(it).time = toc (); toc ()

    name = "Change LOCATION using 'set'";
    it ++;
    printf ("\n*** %s\n", name)
    info(it).name = name;
    info(it).toolkit = tk;info(it).time = 0.0;
    tic ();
    set (hl, "location", "west");
    info(it).time = toc (); toc ()

    name = "Change LOCATION using 'legend'";
    it ++;
    printf ("\n*** %s\n", name)
    info(it).name = name;
    info(it).toolkit = tk;info(it).time = 0.0;
    tic ();
    legend ("location", "south");
    info(it).time = toc (); toc ()

    name = "Change ORIENTATION using 'set'";
    it ++;
    printf ("\n*** %s\n", name)
    info(it).name = name;
    info(it).toolkit = tk;info(it).time = 0.0;
    tic ();
    set (hl, "orientation", "horizontal");
    info(it).time = toc (); toc ()

    name = "Change ORIENTATION using 'legend'";
    it ++;
    printf ("\n*** %s\n", name)
    info(it).name = name;
    info(it).toolkit = tk;info(it).time = 0.0;
    tic ();
    legend ("orientation", "vertical");
    info(it).time = toc (); toc ()

    name = "Change FONTSIZE using 'set'";
    it ++;
    printf ("\n*** %s\n", name)
    info(it).name = name;
    info(it).toolkit = tk;info(it).time = 0.0;
    str = get (hl, "string");
    tic ();
    set (hl, "fontsize", 25);
    info(it).time = toc (); toc ()

    name = "Change FONTSIZE using 'legend'";
    it ++;
    printf ("\n*** %s\n", name)
    info(it).name = name;
    info(it).toolkit = tk;info(it).time = 0.0;
    tic ();
    try
      legend ("fontsize", 20);
    catch
      set (hl, "fontsize", 20);
    end
    info(it).time = toc (); toc ()

    name = "Change STRING using 'set'";
    it ++;
    printf ("\n*** %s\n", name)
    info(it).name = name;
    info(it).toolkit = tk;info(it).time = 0.0;
    str = get (hl, "string");
    tic ();
    set (hl, "string", toupper (str));
    info(it).time = toc (); toc ()

    name = "Change STRING using 'legend'";
    it ++;
    printf ("\n*** %s\n", name)
    info(it).name = name;
    info(it).toolkit = tk;info(it).time = 0.0;
    tic ();
    legend (str);
    info(it).time = toc (); toc ()
    
    name = "Demo 25: subplots with outside legends";
    clf ()
    it ++;
    printf ("\n*** %s\n", name)
    info(it).name = name;
    info(it).toolkit = tk;info(it).time = 0.0;
    tic ()
    x = (1:5)';
    subplot (2,2,1);
    plot (x, rand (numel (x)));
    legend (cellstr (num2str (x)), "location", "northwestoutside");
    subplot (2,2,2);
    plot (x, rand (numel (x)));
    legend (cellstr (num2str (x)), "location", "northeastoutside");
    subplot (2,2,3);
    plot (x, rand (numel (x)));
    legend (cellstr (num2str (x)), "location", "southwestoutside");
    subplot (2,2,4);
    plot (x, rand (numel (x)));
    legend (cellstr (num2str (x)), "location", "southeastoutside");
    info(it).time = toc (); toc ()
    clf ();
    hold on;
    
    name = "Demo 31: subplots with large outside legends";
    it ++;
    printf ("\n*** %s\n", name)
    info(it).name = name;
    info(it).toolkit = tk;info(it).time = 0.0;
    tic ()
    
    subplot (3,1,1);
    plot (rand (1,4));
    xlabel xlabel;
    ylabel ylabel;
    title ("Subplots adjust to the legend placed outside");
    legend ({"1"}, "location", "northeastoutside");
    subplot (3,1,2);
    plot (rand (1,4));
    xlabel xlabel;
    ylabel ylabel;
    legend ({"1234567890"}, "location", "eastoutside");
    subplot (3,1,3);
    plot (rand (1,4));
    xlabel xlabel;
    ylabel ylabel;
    legend ({"12345678901234567890"}, "location", "southeastoutside");

    info(it).time = toc (); toc ()
    clf ();
    hold on;
  endfor

  ninfo = it/2; 
  t = [[info(1:ninfo).time].' [info(ninfo+1:end).time].'];
  graphics_toolkit ("qt")
  close all
  barh (t)
  set (gca, "ygrid", "on", "ydir", "reverse", "layer", "bottom")
  arrayfun (@(ii) text (0.4, ii, info(ii).name, "backgroundcolor", "w"), 1:ninfo);
  legend ("New legend (qt)", "Old legend (gnuplot)", ...
          "location", "northoutside")
  xlabel ("Execution time [s]")
endfunction
