File size: 5,148 Bytes
93fe96e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env python3
"""
Basic Performance Test for Curriculum Assistant
Tests core concepts without external dependencies
"""

import time
import os
from pathlib import Path
import json

class BasicCurriculumTest:
    def __init__(self):
        self.response_cache = {}
        self.sample_data = {
            "loops": {
                "filename": "Week 6 lesson.pptx (1).pdf",
                "page": 1,
                "content": "Loops are programming constructs that solve the problem of repetition. Instead of writing hundreds of print statements to count from 1 to 100, loops allow you to accomplish the same task with just a few lines of code."
            },
            "variables": {
                "filename": "Week 4 Lesson.pptx (2).pdf", 
                "page": 2,
                "content": "Variables are containers that store data values. They allow you to save and reuse information in your programs."
            },
            "functions": {
                "filename": "Week 5 lesson.pptx.pdf",
                "page": 3,
                "content": "Functions are reusable blocks of code that perform specific tasks. They help organize code and avoid repetition."
            }
        }
        print("βœ… Basic test initialized")
    
    def simple_search(self, query):
        """Simple keyword-based search"""
        start_time = time.time()
        
        # Check cache
        if query in self.response_cache:
            print(f"βœ… Cache hit! Response time: {time.time() - start_time:.3f}s")
            return self.response_cache[query]
        
        # Simple keyword search
        query_lower = query.lower()
        results = []
        
        for topic, data in self.sample_data.items():
            if query_lower in topic.lower() or query_lower in data['content'].lower():
                results.append({
                    'topic': topic,
                    'filename': data['filename'],
                    'page': data['page'],
                    'content': data['content'],
                    'score': data['content'].lower().count(query_lower)
                })
        
        # Sort by relevance
        results.sort(key=lambda x: x['score'], reverse=True)
        
        # Generate response
        if results:
            best_result = results[0]
            response = f"πŸ“„ Found in: {best_result['filename']} - Page {best_result['page']}\n\n"
            response += f"Topic: {best_result['topic']}\n"
            response += f"Content: {best_result['content']}\n\n"
            response += f"Found {len(results)} relevant topics"
        else:
            response = f"No relevant content found for '{query}'"
        
        # Cache result
        self.response_cache[query] = response
        
        response_time = time.time() - start_time
        print(f"βœ… Response generated in {response_time:.3f} seconds")
        
        return response

def test_performance():
    """Run performance tests"""
    print("πŸš€ Starting Basic Performance Test...")
    
    # Initialize
    start_time = time.time()
    chatbot = BasicCurriculumTest()
    init_time = time.time() - start_time
    print(f"βœ… Initialization time: {init_time:.3f} seconds")
    
    # Test queries
    test_queries = [
        "loops",
        "variables", 
        "functions",
        "programming",
        "for loop",
        "while loop"
    ]
    
    print(f"\nπŸ§ͺ Testing {len(test_queries)} queries...")
    
    total_time = 0
    for i, query in enumerate(test_queries, 1):
        print(f"\n--- Test {i}/{len(test_queries)}: '{query}' ---")
        
        start_time = time.time()
        response = chatbot.simple_search(query)
        query_time = time.time() - start_time
        total_time += query_time
        
        print(f"Response time: {query_time:.3f}s")
        print(f"Response length: {len(response)} characters")
        print(f"Cache size: {len(chatbot.response_cache)} entries")
        
        # Show first 150 chars of response
        print(f"Response preview: {response[:150]}...")
    
    # Summary
    avg_time = total_time / len(test_queries)
    print(f"\nπŸ“Š Performance Summary:")
    print(f"Total time: {total_time:.3f}s")
    print(f"Average response time: {avg_time:.3f}s")
    print(f"Initialization time: {init_time:.3f}s")
    print(f"Cache hits: {len([q for q in test_queries if q in chatbot.response_cache])}")
    
    # Performance rating
    if avg_time < 0.001:
        rating = "πŸš€ EXCELLENT (< 1ms)"
    elif avg_time < 0.01:
        rating = "βœ… GOOD (< 10ms)"
    elif avg_time < 0.1:
        rating = "⚠️ ACCEPTABLE (< 100ms)"
    else:
        rating = "❌ SLOW (> 100ms)"
    
    print(f"Performance rating: {rating}")
    
    # Comparison with 10-minute response time
    if avg_time < 600:  # 10 minutes = 600 seconds
        improvement = 600 / avg_time if avg_time > 0 else float('inf')
        print(f"πŸš€ This is {improvement:.0f}x faster than the 10-minute response time!")
    else:
        print("❌ This is still slower than the 10-minute response time")

if __name__ == "__main__":
    test_performance()