szaghi / VTKFortran

pure Fortran VTK (XML) API
139 stars 50 forks source link

low performance in vtk_fortran_dataarray_encoder #34

Open hjunqq opened 2 years ago

hjunqq commented 2 years ago

the code like

  code = ''
  do n=1, size(x, dim=1)
    code = code//str(n=u(n))//' '//str(n=v(n))//' '//str(n=w(n))// &
                 str(n=x(n))//' '//str(n=y(n))//' '//str(n=z(n))
  enddo

in vtk_fortran_dataarray_encoder.f90 takes a long time to execute when a large amount of data needs to be processed

szaghi commented 2 years ago

Hi @hjunqq

I know, but vtk_fortran_dataarray_encoder is the encoder for ASCII files that are not tailored for a large amount of data.

If you have to write large files I strongly suggest using a raw binary encoder.

Kind regards

hjunqq commented 2 years ago

I modify the code like that:

  size_n = size(x,dim=1)
  l = DI1P+1
  sp = 0
  code = repeat(' ',l*size_n)
  do n = 1,size_n
      code(sp+1:sp+l) = str(n=x(n))
      sp = sp + l
  enddo

it has better performance, but doesnot as elegant as the code you wrote.

35

szaghi commented 2 years ago

Hi @hjunqq sorry for my delay. Yes, there is room for improvement, but for the ASCII encoder, I was focused on clearness, conciseness, and maintainability rather than performance just because for larger files the raw-binary encoder is the right option. Anyway, you patch is fine for me.

Kind regards