Блог пользователя efimovpaul

Автор efimovpaul, история, 3 года назад, По-английски

Hello, Codeforces!!


Guys, how do you stress-test your solutions? I know at least three possible ways to do it.

1)Right in your solution file
Write second stress-solution ( definitly correct, but quite slow ), generator, checker, ect. right in your solution file as functions and call functions from main.
I personally use this variant, it is fast and convinient. But there is one problem using this method.. When you have your solution fixed, you have to comment all your stress-code.. I have a trick: just make copy of your file before adding stress-testing functions and add them in your second file, after debugging you will have to just fix jour solution in the first file.

2)Python script
Some people write Python scripts to stress their solutions. You have two programs: solution with bug and stress-solution. So you can just generate tests, lauch your solutions, check answers, etc. from Python script.

3)Bash or maybe Bat scripts
Method is idiologically similar to the 2)Python script, but you write bash/bat scripts.


Which method do you use? Or maybe you have your own techniques, share in comments.

  • Проголосовать: нравится
  • +54
  • Проголосовать: не нравится

»
3 года назад, # |
  Проголосовать: нравится +95 Проголосовать: не нравится

Too much stress can be detrimental to their performance. Codes need a caring and minimal stress environment to foster their growth.

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    aahahha, nice joke
    But I think you are right, sometimes it is better to try to talk to it, look, search for bug just watching code

»
3 года назад, # |
  Проголосовать: нравится +32 Проголосовать: не нравится

Big eye big brain method: Try to come up with nasty inputs and run them.

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    Yeah!! Of course you are right. It is supposed that you have already tried some tricky cases before you write stress tests.

    • »
      »
      »
      3 года назад, # ^ |
      Rev. 2   Проголосовать: нравится +6 Проголосовать: не нравится

      Oh, I misread. In China, when participating in the provincial/national Olympiad, we do something that is called '对拍' which is basically writing a brute force solution and a generator, then using a bat script to connect those three and try to find a case that fail on the better solution. You have to be absolutely sure that the brute force solution is correct though. That's probably a mix of (1) and (3) mentioned above.

      • »
        »
        »
        »
        3 года назад, # ^ |
          Проголосовать: нравится +8 Проголосовать: не нравится

        hm.. Is using Bat script to combine solutions and generator more convenient than just calling them from main program (of course I am talking about cases when all functions are written using one programming language) ?

        • »
          »
          »
          »
          »
          3 года назад, # ^ |
            Проголосовать: нравится +3 Проголосовать: не нравится

          Well that's probably because we don't use 'void solve()' or something like this, we write a ton of stuff in main(). Maybe I can try calling from main program later...

          • »
            »
            »
            »
            »
            »
            3 года назад, # ^ |
              Проголосовать: нравится 0 Проголосовать: не нравится

            When I have tried writing all staff in other function and kerping main function minimalized, I found it really convenient

»
3 года назад, # |
  Проголосовать: нравится +11 Проголосовать: не нравится

I use FastOlympicCoding's stress in sublime text. And it's usage is like the second one. All we need is a correct solution, a wrong solution and a generator file.

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Hi! Firstly I use ubuntu so the bash script may be diffrent if you use windows.I published the codes here.

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    in Windows it is Bat scripts, they are a bit different, but I think it Will be interesting to try to use your script on Linux, thank you!!

»
3 года назад, # |
  Проголосовать: нравится +6 Проголосовать: не нравится

Check this

»
3 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

Here's the bash command that I use for stress testing.

Command
  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    do you understand what is happening there? I will be glad if you give me some good resources to learn bash commands, I was quiet surprised when I found out that it is not easy to find full bash-learning courses and videos.

»
3 года назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

Using https://polygon.codeforces.com/ is also an option

»
3 года назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

All I do is write brute force and use this and this

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    you do not even write scripts connecting these utilities? is stress-testing fast enough using this method?

»
3 года назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

I've developed my own system for stress testing, which also allows me to do a ton of customizations, and run multiple tests in parallel.

cfstress.com

Although behind the scenes, it'd fall under category 3.

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    wow, nice job!! is only online version available? online versions are not allowed to use during some olympiads, maybe you have something like "portable version"?

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    in addition to the previous comment, it asks the number of CF problem, so is it important for problem to exist on CF? you get input format from there? is it possible to make your utility work using just problem's statement text?

    • »
      »
      »
      3 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      No, it's not important for the problem to exist on Codeforces (for example, I also use it for Atcoder Beginner Contests). But that feature is only available on the portable version.

      However, don't get the impression that it uses Machine Learning to parse problems and generate test automatically. It doesn't. But I have created various scripts, header files and macros that allow me to feed the data in a fixed format and it generates the test cases off of that. There's definitely a little coding required for each problem, but it's just 5 to 10 minutes of effort per problem. (If it takes more than 15 minutes, it's not worth stress testing IMO).

      For example, for the last Edu Round, it took ms around 30 minutes to create generators for all 6 problems.

      • »
        »
        »
        »
        3 года назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        Yeah, I got it, so 30 minutes for 6 problems is a good result.

        BTW: Did you try to use ML somewhere in Competitive Programming?

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I use CodePal

»
3 года назад, # |
Rev. 3   Проголосовать: нравится +3 Проголосовать: не нравится

I can suggest IFDEF for C++, and if statement check for python. If you write ur code in python, you can create decorator which checks if code is used locally (for example using os.getlogin()), and place it right before ur stress tests and they will be skipped.

import os

def ignore(func):
    if os.getlogin() == "doreshnikov":
        func()
    else:
        pass

@ignore
def stress():
    print(123)
»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Why not to always use first option + #ifdef? The only downside is that you should be a bit more careful with random and multitests, but if those problems arise, then you are probably doing something wrong.

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    yes, I think that it is a good solution to use ifdef some people offered it, I will try this one. Thanks!