Jump to content
dmitrybv

TValue.IsType<String> for Variant(Interface) is very slow.

Recommended Posts

Hello.
The following code takes 0.1 seconds on my computer.
In my opinion, this is too slow.


 

procedure TFormSimpleDraw2.Button4Click(Sender: TObject);
var
  ItfcVarValue: TValue;
  Itfc: IInterface;
  VarValue: Variant;
  Res: Boolean;
begin
  Itfc := TInterfacedObject.Create;
  VarValue := Itfc;
  ItfcVarValue := TValue.From<Variant>(VarValue);

  var TimeSpan := TThread.GetTickCount64;
  Res := ItfcVarValue.IsType<String>;
  Memo1.Lines.Add(FloatToStr((TThread.GetTickCount64 - TimeSpan) / 1000) + ' sec; Result = ' + Res.ToString(TUseBoolStrs.True));
end;

 

Result in Memo1

Memo1.Text = 0.109 sec; Result = False

 

Most likely the reason is related to the occurrence of an internal exception which is then suppressed somewhere.

 

----
 

procedure TFormSimpleDraw2.Button5Click(Sender: TObject);
var
  Res: Boolean;
  ItfcVarValue: TValue;
begin
  ItfcVarValue := TValue.From<IInterface>(TInterfacedObject.Create);

  var TimeSpan := TThread.GetTickCount64;
  Res := ItfcVarValue.IsType<String>;
  Memo1.Lines.Add(FloatToStr((TThread.GetTickCount64 - TimeSpan) / 1000) + ' sec; Result = ' + Res.ToString(TUseBoolStrs.True));
end;

 

Memo1.Text = 0 sec; Result = False

 

 

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×